I’m trying to draw secondary Y axes to a chart same as Pareto chart
The expected chart
but keep showing as the following
My current chart
Any help or hint would be appreciated
this is my code
` $dataSeriesLabels = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, ‘ErrorFrequency!$C$1’, null, 1),
];
$xAxisTickValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, ‘ErrorFrequency!$B$2:$B$’.($this->rowIndex-1), null, $totalRowsCount),
];
$dataSeriesValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'ErrorFrequency!$C$2:$C$'.($this->rowIndex-1), null, $totalRowsCount),
];
$series = new DataSeries(
DataSeries::TYPE_BARCHART,
DataSeries::GROUPING_CLUSTERED,
range(0, count($dataSeriesValues) - 1),
$dataSeriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
// second axis
$dataSeriesLabels2 = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'ErrorFrequency!$E$1', null, 1),
];
$dataSeriesValues2 = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'ErrorFrequency!$E$2:$E$'.($this->rowIndex-1), null, $totalRowsCount),
];
// Build the dataseries
$series2 = new DataSeries(
DataSeries::TYPE_LINECHART,
DataSeries::GROUPING_STANDARD , //GROUPING_STACKED, //GROUPING_STANDARD,
range(0, count($dataSeriesValues2) - 1),
$dataSeriesLabels2,
[],
$dataSeriesValues2
);
$series2->setPlotDirection(DataSeries::DIRECTION_VERTICAL);
$plotArea = new PlotArea(null, [$series,$series2]);
$legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new Title('Pareto Chart - Error Types (20% of errors cause 80% of issues)');
$yAxisLabel = new Title('Error Counts');
$secondaryYAxisLabel = new Title('Secondary Axis Label'); // Adjust as needed
$yaxis = new Axis();
$xaxis = new Axis();
$yaxis->setAxisOptionsProperties('low', null, null, null, null, null, -20, 20, null, null);
//$yaxis->setLineParameters('FFFFFF',100,Axis::EXCEL_COLOR_TYPE_ARGB);
$xaxis->setAxisOptionsProperties('low', null, null, null, null, null, 0, 0, null, null);
// Create the chart
$chart = new Chart(
'chart',
$title,
$legend,
$plotArea,
true,
DataSeries::EMPTY_AS_GAP,
null, // xAxisLabel
$yAxisLabel, // yAxisLabel
null, // xAxis
null, // yAxis
null, // majorGridlines
null, //minor Gridlines
$secondaryYAxisLabel
);
$chart->setTopLeftPosition('I3');
$chart->setBottomRightPosition('Z25');
$worksheet = $this->spreadsheet->getActiveSheet();
$worksheet->addChart($chart);`