iT邦幫忙

1

PHPExcel YAxisLabel 要如何才能水平顯示?

  • 分享至 

  • xImage

請問該如何設定PHPExcel 才能將 YAxisLabel 由垂直(圖一)改成水平(圖二)

圖一
https://ithelp.ithome.com.tw/upload/images/20200903/20114266pFJQ6Irsa3.png

圖二
https://ithelp.ithome.com.tw/upload/images/20200903/20114266lspPuO1b2L.png

    $dataseriesLabels = array(
        new PHPExcel_Chart_DataSeriesValues('String', "數據!\${$valueLabel}\$1", NULL, 1),  //Data1
        new PHPExcel_Chart_DataSeriesValues('String', "數據!\${$upLabel}\$1", NULL, 1),
        new PHPExcel_Chart_DataSeriesValues('String', "數據!\${$downLabel}\$1", NULL, 1),
    );
    $x = [];
    for ($i = 1; $i <= $dataCount; $i++) {
        $x[] = $i;
    }

    $xAxisTickValues = array(
        new PHPExcel_Chart_DataSeriesValues('String', NULL, NULL, $dataCount, $x), // 0~6
    );

    $dataSeriesValues = array(
        new PHPExcel_Chart_DataSeriesValues('Number', "數據!{$valueRange}", null, $dataCount, array(), 'none'),
        new PHPExcel_Chart_DataSeriesValues('Number', "數據!{$upRange}", null, $dataCount, array(), 'none', 'C21305'),
        new PHPExcel_Chart_DataSeriesValues('Number', "數據!{$downRange}", null, $dataCount, array(), 'none', 'C21305'),
    );

    $series = new PHPExcel_Chart_DataSeries(
        PHPExcel_Chart_DataSeries::TYPE_LINECHART,
        PHPExcel_Chart_DataSeries::GROUPING_STANDARD,    // plotGrouping
        range(0, count($dataSeriesValues) - 1),           // plotOrder
        $dataseriesLabels,                              // plotLabel
        $xAxisTickValues,                               // plotCategory
        $dataSeriesValues
    );
    $series->setLineWidth(1.5);
    $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);

    $plotarea = new PHPExcel_Chart_PlotArea(null, array($series));
    
    $title = new PHPExcel_Chart_Title($title);
    $xAxisLabel = new PHPExcel_Chart_Title($xAxisLabel);
    //yAxisLabel 請問這裡該如何設定,才能改成水平?
    $layout = new PHPExcel_Chart_Layout();
    $yAxisLabel = new PHPExcel_Chart_Title($yAxisLabel, $layout);

    $yAxis = new PHPExcel_Chart_Axis();
    $yAxis->setAxisOptionsProperties('nextTo', null, null, null, null, null, $yAxisMinTick, $yAxisMaxTick, $yAxisInterval);

    $multiTypeChart = new PHPExcel_Chart($title, $title, null, $plotarea, true, 0, null, $yAxisLabel, null, $yAxis);

    $multiTypeChart->setTopLeftPosition($locLeft);
    $multiTypeChart->setBottomRightPosition($locBottom);
ckp6250 iT邦好手 1 級 ‧ 2020-09-03 16:59:35 檢舉
題外話,供參考。
用 PHPExcel 做圖表會不會太辛苦了?
用 Google Charts 製作圖表簡單許多,傳幾個參數進去,要什麼圖有什麼圖。
kuanhuayu iT邦新手 5 級 ‧ 2020-09-03 19:37:17 檢舉
因為客戶需求資料除了匯出Excel外還要產生相關的圖表,而且公司內部部份電腦依公司規定不能連外網,所以只好用PHPExcel來製作
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答