phpexcel chart secondary axis

35 Views Asked by At

enter image description here

If you run the code below, a graph will be created like the image above.

What I want is to use the value of B as the auxiliary axis, as shown in the image below.

How can I fix it?

enter image description here

$dataseriesLabels1 = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1),   //  Temperature
);
$dataseriesLabels2 = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),   //  Rainfall
);

$xAxisTickValues = array(
    new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$13', NULL, 12),    //  Jan to Dec
);

$dataSeriesValues1 = array(
    new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', NULL, 12),
);
$series1 = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_BARCHART,       // plotType
    PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED,  // plotGrouping
    range(0, count($dataSeriesValues1)-1),          // plotOrder
    $dataseriesLabels1,                             // plotLabel
    $xAxisTickValues,                               // plotCategory
    $dataSeriesValues1                              // plotValues
);

$series1->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$dataSeriesValues2 = array(
    new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12),
);
$series2 = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_LINECHART,      // plotType
    PHPExcel_Chart_DataSeries::GROUPING_STANDARD,   // plotGrouping
    range(0, count($dataSeriesValues2)-1),          // plotOrder
    $dataseriesLabels2,                             // plotLabel
    NULL,                                           // plotCategory
    $dataSeriesValues2                              // plotValues
);

//  Create the chart
$chart = new PHPExcel_Chart(
    'chart1',       // name
    $title,         // title
    $legend,        // legend
    $plotarea,      // plotArea
    true,           // plotVisibleOnly
    0,              // displayBlanksAs
    NULL,           // xAxisLabel
    NULL            // yAxisLabel
);
0

There are 0 best solutions below