Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Chart.js set chart title, name of x axis and y axis?

Does Chart.js (documentation) have option for datasets to set name (title) of chart (e.g. Temperature in my City), name of x axis (e.g. Days) and name of y axis (e.g. Temperature). Or I should solve this with css?

var lineChartData = {     labels : ["January","February","March","April","May","June","July"],     datasets : [         {             fillColor : "rgba(220,220,220,0.2)",             strokeColor : "rgba(220,220,220,1)",             pointColor : "rgba(220,220,220,1)",             pointStrokeColor : "#fff",             pointHighlightFill : "#fff",             pointHighlightStroke : "rgba(220,220,220,1)",             data : [data]         }     ]  } 

Realy thanks for help.

like image 633
DaniKR Avatar asked Jan 12 '15 21:01

DaniKR


People also ask

How do you name a chart with X and Y axis?

Click the chart, and then click the Chart Design tab. Click Add Chart Element > Axis Titles, and then choose an axis title option. Type the text in the Axis Title box. To format the title, select the text in the title box, and then on the Home tab, under Font, select the formatting that you want.

How do I add a title to Chartjs?

The example below would enable a title of 'Custom Chart Title' on the chart that is created. const chart = new Chart(ctx, { type: 'line', data: data, options: { plugins: { title: { display: true, text: 'Custom Chart Title' } } } }); Copied!


2 Answers

In Chart.js version 2.0, it is possible to set labels for axes:

options = {   scales: {     yAxes: [{       scaleLabel: {         display: true,         labelString: 'probability'       }     }]   }      } 

See Labelling documentation for more details.

like image 142
andyhasit Avatar answered Sep 21 '22 21:09

andyhasit


For Chart.js version 3

options = {   scales: {     y: [{       title: {         display: true,         text: 'Your Title'       }     }]   }      } 
like image 38
Ayenew Yihune Avatar answered Sep 20 '22 21:09

Ayenew Yihune