Search code examples
phpopentbs

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


I am trying to create a stacked bar chart as shown below embedded on a slide of a PowerPoint template. When I run my script below I am getting an error.

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.

As far as I can see my series are clearly defined along with each of the two labels for the x axis.

Where am I going wrong and how can I resolve this error?

Table Definition in Template

Stacked Bar Chart Sample Image

$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);

Solution

  • I modified my $NewValues array for each of the series to be an array of two elements, with the first element being the x axis values and the second element being the y axis value. The x axis value was an array of two values ("Closed On Time", "Closed Late"), and the y axis was an array of two elements (one element being zero and the other being the value for that x value (either closed on time or closed late)

    Output Graph

    Output Stacked Bar Chart

    Example

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

    Solution Code

    $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);