Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js Subtitle won't display

I can't get the subtitle for my pie chart to work. It just won't show.

I was trying this: https://www.highcharts.com/docs/chart-concepts/title-and-subtitle

options: {
    pieceLabel: {
        showZero: true,
        fontColor: '#fff',
        fontFamily: "'Maven Pro', sans-serif",
        position: 'default'
    },
    title: {
        display: true,
        position: 'top',
        text: 'Screened',
        fontSize: 14
    },
    subtitle:{
        text: 'Subtitle',
    },
    legend: {
        display: false
    }
}

My chart displays fine, so I have only shared the options part of the code.

I'm not sure if subtitles are supported by chart.js. If not, suggestions for line break in title or any other substitute are welcome.

like image 235
Leah Avatar asked Nov 28 '17 10:11

Leah


People also ask

Does chart js use SVG?

Other than that the most obvious distinction between the two is that Chart. js is canvas based, while d3. js is mainly about SVG.

How do I set the size of a ChartJS?

To set the chart size in ChartJS, we recommend using the responsive option, which makes the Chart fill its container. You must wrap the chart canvas tag in a div in order for responsive to take effect. You cannot set the canvas element size directly with responsive .

Does chart JS work with TypeScript?

TypeScript Typings Chart. js provides a way to augment built-in types with user-defined ones, by using the concept of "declaration merging".


1 Answers

In the title text property, you can pass in a string array and each item will break onto a new line.

text: ['Title','Subtitle'],

Subtitle example

Here is a working example.

like image 132
David Avatar answered Sep 29 '22 19:09

David