JF-Mechs
JF-Mechs

Reputation: 1081

How to set 2 y-axis title (and/or label) on chartjs?

I know that setting a title or a label on chartjs' charts takes only a few properties on chart options.

...
yAxes: [{
    scaleLabel: {
        display: true,
        labelString: "My Chart"
    }
}]
...

but, is there anyway to set 2 title/label on chartjs ? I'd like to add some sort of a sub-title.

Upvotes: 1

Views: 1488

Answers (1)

beaver
beaver

Reputation: 17647

There is no option for yAxes subtitles but you can use a secondary yAxis properly configured:

scales : {
    yAxes : [{
            scaleLabel : {
                display : true,
                labelString : "subtitle",
                fontStyle : 'italic'
            }
        }, {
            display : true,
            gridLines : {
                display : false,
                color : 'transparent'
            },
            ticks : {
                display : false
            },
            scaleLabel : {
                display : true,
                labelString : "My Chart title",
                fontStyle : 'bold',
                fontSize : 14
            }
        }
    ]
}

Check this fiddle: https://jsfiddle.net/beaver71/jg7Lgc43/

Upvotes: 2

Related Questions