Search code examples
canvasjs

Angle labels in opposite direction?


Currently, it seems that CanvasJS only supports angling labels in one direction (with the baseline on the left), as shown in the image below. I would like to rotate the text in the opposite direction (With the baseline for the text being on the right), as shown by the arrows.

CanvasJS chart labels

So far, I have tried setting the axisX labelAngle to 90, 270, -45, -90, and -270. None of these have resulted in shifting the baseline to the right like I want, and have all forced the text to a max of 90 degrees with the baseline on the left.

Is this possible in the current version? @Devs: If not available in current version, would it be possible to add in support for this?


Solution

  • You can set angle to negative value to make it rotated the other way-round, as shown in this screenshot. enter image description here Here is an example.

    var chart = new CanvasJS.Chart("chartContainer",
        {
          axisX:{
            title: "labels at -45 deg",
            labelAngle: -45
          },
          data: [
          {
            type: "column",
            dataPoints: [
    
            { x: 10, y: 71, label: "cat 1" },
            { x: 20, y: 55, label: "cat 2" },
            { x: 30, y: 50, label: "cat 3" },
            { x: 40, y: 65, label: "cat 4" },
            { x: 50, y: 95, label: "cat 5" },
            { x: 60, y: 68, label: "cat 6" },
            { x: 70, y: 28, label: "cat 7" },
            { x: 80, y: 34, label: "cat 8" },
            { x: 90, y: 14, label: "cat 9" }
            ]
          }
          ]
        });
    
        chart.render();
    <script src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>
    <div id="chartContainer" style="height: 360px; width: 100%;"></div>