如何在PHP电子表格的3D柱状图中使标签值以粗体样式显示?

huangapple go评论73阅读模式
英文:

how can i make my label values with BOLD style in a 3D bar chart in phpspreadsheet

问题

你可以使用以下方式来设置标签值为粗体:

// Set the Labels for each data series we want to plot
$dataSeriesLabelsTotals = [
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$H$30', null, 1, array('bold' => true)),   // Quantity OK
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$J$30', null, 1, array('bold' => true)),     // Quantity NOK
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$L$30', null, 1, array('bold' => true)),     // Quantity Re-work
    new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$R$30', null, 1, array('bold' => true)),     // Quantity total
];

在每个标签值的定义中,加入 array('bold' => true) 即可使标签值变为粗体。

希望对你有所帮助。

英文:

Hello i was able to create a clustered 3D bar chart using PHPspreadsheet, version 1.23

However i want my label values, for each each column, to become more visible, by stylizing them to become BOLD. However after several tries, nothing worked here is my code for my chart


        $worksheet = $this->spreadsheet->getActiveSheet();

        // Set the Labels for each data series we want to plot
        //     Datatype
        //     Cell reference for data
        //     Format Code
        //     Number of datapoints in series
        //     Data values
        //     Data Marker
        $dataSeriesLabelsTotals = [
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$H$30', null, 1),   // Quantity OK
        //    new DataSeriesValues(),
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$J$30', null, 1),     // Quantity NOK
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$L$30', null, 1),     // Quantity Re-work
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$R$30', null, 1),     // Quantity total
        ];
        // Set the X-Axis Labels
        //     Datatype
        //     Cell reference for data
        //     Format Code
        //     Number of datapoints in series
        //     Data values
        //     Data Marker
        $xAxisTickValuesTotals = [
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$20:$A$21', null, 1), // Labels X
        ];
        // Set the Data values for each data series we want to plot
        //     Datatype
        //     Cell reference for data
        //     Format Code
        //     Number of datapoints in series
        //     Data values
        //     Data Marker
        $dataSeriesValuesTotals = [
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$H$' . ($cursor + 1) . ':$I$'. ($cursor + 1) , null, 1), 
            // new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$Z$3' , null, 1),        // Quantity OK
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$J$' . ($cursor + 1) . ':$K$'. ($cursor + 1) , null, 1),
            // new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$Z$3' , null, 1),        // Quantity NOK
            new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$L$' . ($cursor + 1) . ':$M$'. ($cursor + 1) , null, 1),
            // new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$Z$3' , null, 1),        // Quantity Re-work
          new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$R$' . ($cursor + 1) . ':$S$'. ($cursor + 1) , null, 1),      // Quantity total 
        ];

        // Build the dataseries
        $series1 = new DataSeries(
            DataSeries::TYPE_BARCHART_3D, // plotType
            DataSeries::GROUPING_CLUSTERED, // plotGrouping
            range(0, count($dataSeriesValuesTotals) - 1), // plotOrder
            $dataSeriesLabelsTotals, // plotLabel
            $xAxisTickValuesTotals, // plotCategory
            $dataSeriesValuesTotals // plotValues
        );
    
        // Set additional dataseries parameters
        //     Make it a vertical column rather than a horizontal bar graph
        $series1->setPlotDirection(DataSeries::DIRECTION_VERTICAL);



        // Set labels in chart columns
        $layoutTotals = new Layout();
        $layoutTotals->setShowVal(true);

       
      

        // Set the series in the plot area
        $plotAreaTotals = new PlotArea($layoutTotals, [$series1]);
   
        // Set the chart legend
        $legendTotals = new ChartLegend(ChartLegend::POSITION_LEFT, null, false);

        

        $titleTotals = new Title('TOTALS');


        // Create the chart
        $chartTotals = new Chart(
            'Chart Totals', // name
            $titleTotals, // title
            $legendTotals, // legend
            $plotAreaTotals, // plotArea
            false, // plotVisibleOnly
            DATASERIES::EMPTY_AS_GAP, // displayBlanksAs
            null, // xAxisLabel
            null,
              // yAxisLabel
         
           
        );

    

    
        // Set the position where the chart should appear in the worksheet
        $chartTotals->setTopLeftPosition('B' . ($cursor + 3));
        $chartTotals->setBottomRightPosition('M' . ($cursor + 20));

     
        // Add the chart to the worksheet
        $worksheet->addChart($chartTotals);

And here is how my chart is looking . As you can see the 2 in the green column has less visibility and i want to make the value Bold

如何在PHP电子表格的3D柱状图中使标签值以粗体样式显示?

Thank You

答案1

得分: 0

未找到如何更改数据标签值的样式,但我成功解决了我的问题,通过改变值的颜色来实现一个解决方法。为此,我简单地创建了一个新的ChartColor对象,使用特定的颜色,然后调用SetLabelFontColor方法来更改值的颜色,如下所示:

$colors = new ChartColor("0D0078");

// 设置图表列中的标签
$layoutTotals = new Layout();

$layoutTotals->setShowVal(true);
$layoutTotals->setLabelFontColor($colors);
英文:

Didn't found out how to chance the style of the value of the Data label, however i managed to solve my problem doing a work around, by changing the color of the values. To do that, i simple created a new ChartColor object with a specific color and then called the SetLabelFontColor method to change the values color, like this

$colors= New ChartColor("0D0078");
       

 

        // Set labels in chart columns
        $layoutTotals = new Layout();

        $layoutTotals->setShowVal(true);
        $layoutTotals->setLabelFontColor($colors);

huangapple
  • 本文由 发表于 2023年2月27日 17:37:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578791.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定