openTBS/PHP - 如何创建堆叠条形图?

openTBS/PHP - How do I create a stacked bar chart?

我正在尝试创建一个堆叠条形图,如下所示,嵌入到 PowerPoint 模板的幻灯片中。当我 运行 下面的脚本出现错误时。

TinyButStrong Error OpenTBS Plugin: (ChartChangeSeries) 'chart3' : unable to found series 'Series 3' in the chart 'chart3'. The process is ending, unless you set NoErr property to true.

据我所知,我的系列与 x 轴的两个标签中的每一个都有明确的定义。

我哪里出错了,我该如何解决这个错误?

$ecdClosureStatus = getClosureChartData('ECD');
    $ChartNameOrNum = 'chart3'; // Title of the shape that embeds the chart
    $ChartRef = 'chart3'; // Title of the shape that embeds the chart
    $SeriesNameOrNum = 'Series 1';
    $NewLegend = "Closed On Time";
    $NewValues =    array(


(int)$ecdClosureStatus['ClosedOnTime'],
                                    0
                                );
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

$SeriesNameOrNum = 'Series 2';
$NewLegend =    'Closed 1-30 Days Late';
$NewValues =    array(
                                    0,
                                    (int)$ecdClosureStatus['OneToThirtyDaysLate']
                                );
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

$SeriesNameOrNum = 'Series 3';
$NewLegend =        'Closed 31-60 Days Late';
$NewValues =    array(
                                    0,
                                    (int)$ecdClosureStatus['ThirtyOneToSixtyDaysLate']
                                );
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

$SeriesNameOrNum = 'Series 4';
$NewLegend =    'Closed 61-90 Days Late';
$NewValues =        array(
                                    0,
                                    (int)$ecdClosureStatus['SixtyOneToNinetyDaysLate']
                                );
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

$SeriesNameOrNum = 'Series 5';
$NewLegend = 'Closed >90 Days Late';
$NewValues =    array(
                                    0,
                                    (int)$ecdClosureStatus['ClosedMoreThanNinetyDaysLate']
                                );
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

您的代码似乎 ok.The 问题可能来自系列 #3,它可能没有像您期望的那样在内部命名。仔细检查电子表格查看器中的名称,末尾不得有空格。您也可以尝试使用“修改 Excel 女士的数据”按钮。

不过您可以使用新的 OpenTBS 命令 return 图表数据。它在 OpenTBS beta version 1.9.5 中可用,但它很稳定。

命令:

$data = $TBS->PlugIn(OPENTBS_CHART_INFO, 'chart3');   
var_dump($data);

我将每个系列的 $NewValues 数组修改为两个元素的数组,第一个元素是 x 轴值,第二个元素是 y 轴值。 x 轴值是一个包含两个值的数组 ("Closed On Time", "Closed Late"),y 轴是一个包含两个元素的数组(一个元素为零,另一个元素是该 x 值的值 (准时关闭或延迟关闭)

输出图

例子

 $NewValues =   array(array('Closed On Time', 'Closed Late'), array(
                                        (int)$ecdClosureStatus['ClosedOnTime'],
                                        0
                                    ));

解决方案代码

$ecdClosureStatus = getClosureChartData('ECD');
    $ChartNameOrNum = 'chart3'; // Title of the shape that embeds the chart
    $ChartRef = 'chart3'; // Title of the shape that embeds the chart
    $SeriesNameOrNum = 'Series 1';
    $NewLegend = "Closed On Time";
    $NewValues =    array(array('Closed On Time', 'Closed Late'), array(
                                        (int)$ecdClosureStatus['ClosedOnTime'],
                                        0
                                    ));
    $TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

    $SeriesNameOrNum = 'Series 2';
    $NewLegend =    '1-30 Days Late';
    $NewValues =        array(array('Closed On Time', 'Closed Late'), array(
                                        0,
                                        (int)$ecdClosureStatus['OneToThirtyDaysLate']
                                    ));
    $TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

    $SeriesNameOrNum = 'Series 3';
    $NewLegend =        ' 31-60 Days Late';
    $NewValues =        array(array('Closed On Time', 'Closed Late'), array(
                                        0,
                                        (int)$ecdClosureStatus['ThirtyOneToSixtyDaysLate']
                                    ));
    $TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

    $SeriesNameOrNum = 'Series 4';
    $NewLegend =    '61-90 Days Late';
    $NewValues =            array(array('Closed On Time', 'Closed Late'), array(
                                        0,
                                        (int)$ecdClosureStatus['SixtyOneToNinetyDaysLate']
                                    ));
    $TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);

    $SeriesNameOrNum = 'Series 5';
    $NewLegend = ' >90 Days Late';
    $NewValues =        array(array('Closed On Time', 'Closed Late'), array(
                                        0,
                                        (int)$ecdClosureStatus['MoreThanNinetyDaysLate']
                                    ));
    $TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);