ChartJS Labels Rotation

Answered
0
0

Hi,

how can I change the orientation or rotation of the datalabels? Or is there a multiline option?

The property “myChart.Options.DataLabel.Rotation” changes the orientation within the bar chart, but I want to change the labels of the x-axis.

THX!

Stephan

Attachment
  • You must to post comments
Best Answer
0
0

There’s not a C# property for this, so you have to do it in JavaScript.

You can do this through the following line of JavaScript code:
this.widget.chart.scales['x-axis-0'].labelRotation = 90

You can use the Eval function to call JavaScript from C# code
chartJS1.Eval(@"this.widget.chart.scales['x-axis-0'].labelRotation = 90");

You MUST put this code as part of the Page Appear Event. If you put the code as part of the Page Load event, you will get the following error: “Cannot read properties of undefined (reading ‘chart’)” Essentially, you must make sure the chart in the widget is initialized before this code runs.

private void Page1_Appear(object sender, EventArgs e)
{
chartJS1.Eval(@"this.widget.chart.scales['x-axis-0'].labelRotation = 90");
}

You can add labels in the Page Load event like so:

chartJS1.Labels = new string[] {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};

You can use similar code to modify the rotation of the labels on the y axis:
this.widget.chart.scales['y-axis-0'].labelRotation = 45

I have attached a sample.

-Julie

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.