We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to sync dual axis in chart - Aspose Cells

Hello Aspose Team,

I got a dual vertical axis chart with different unit for each axis.
(see in image below).
double_axis_chart.PNG (40.1 KB)

My issue is that left and right axis are not sync.
I mean that the duration curve line must be in “touch” with the top of “Total” stacked column (as they have both same value).
Instead it’s very dependant of the value in table.

I want to scale right axis max value according to left axis max value, but I’m unable to found out the max value for left axis.

I try to use :

  chart.getValueAxis().getMaxValue();
  chart.getValueAxis().getMajorUnitScale();

but I got null or 0 from these methods.

Do you know from which method I can get a value like 35 if the left axis max value is 35.00 %

Best regards,
Thomas

@ThomasP6,

Could you please provide the following:

  1. Your input Excel file (if any) containing data source for the chart.
  2. Your output Excel file containing your undesired chart by Aspose.Cells API.
  3. Your complete runnable sample code to generate the (undesired) chart in 2).
  4. A sample Excel file containing your desired chart in it, you may create the chart manually in MS Excel.

You may try to first call Chart.calculate() method before retrieving values from those attributes if it works. Please note, if those major unit scale and maximum values are set “Automatic” in axis formats, then you cannot get values for those attributes precisely.

PS. please zip the files prior attaching here.

1 Like

Hello @Amjad_Sahi,

Thanks for your response !

chart.calculate() was the key.

By using this code, it now works !

      // Divide total duration in seconds by number of seconds in 1 day
      const percentToDurationRatio =
        columnStackedChartDetails.curveTotalDuration / 86400;

      // Pre render chart to get axis values
      chart.calculate();

      // Set secondary axis min value according to primary axis min value
      chart
        .getSecondValueAxis()
        .setMinValue(
          chart.getValueAxis().getMinValue() * percentToDurationRatio
        );

      // Set secondary axis max value according to primary axis max value
      chart
        .getSecondValueAxis()
        .setMaxValue(
          chart.getValueAxis().getMaxValue() * percentToDurationRatio
        );

Regards,
Thomas

@ThomasP6,

Good to know that your issue is sorted out by the suggested line of code. Feel free to write us back if you have further queries or issue, we will be happy to assist you soon.