Home Forums StockChart Support Set width of chart only and not labels

Set width of chart only and not labels

Viewing 2 posts - 1 through 2 (of 2 total)
  • #36614

    Hi,

    I am trying to set width of the chart only and not the entire chart container. In this fiddle for example, https://jsfiddle.net/mustadirmahmood/ovwebL51/9/, I set the width to 320px but this 320px includes the labels and the y-axis title as well. Is there a way I can set width for only the chart and not the entire chart container?

    I also want to implement the same thing for height.

    Please let me know if this is possible?

    Thanks

    #36627

    @mustadirmahmood,

    You can set chart’s width & height dynamically by keeping plot-area width & height to be a constant value by manually calculating with the help of axis bounds. Please find the code-snippet below.

      var axisXBounds = chart.axisX[chart.axisX.length - 1].get("bounds");
      var axisYBounds = chart.axisY[chart.axisY.length - 1].get("bounds");
    
      var plotAreaWidth = 300;
      var plotAreaHeight = 300;
    
      var chartWidth = axisXBounds.x1 + plotAreaWidth;
      var chartHeight = chart.height - (axisYBounds.y2) + axisYBounds.y1 + plotAreaHeight;
    
      chart.set("width", chartWidth, false);
      chart.set("height", chartHeight);

    Please take a look at this JSFiddle for a working example.

    calculate-width-height-of-the-chart

    —-
    Ranjitha R
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.