Categories > OpenTBS with DOCX >

Dynamically changing or adding/removing legends and related data in charts

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jonathan Hill
Date: 2017-03-12
Time: 18:55

Dynamically changing or adding/removing legends and related data in charts

I have a pie chart with 2 legends and the related pie and I want to be able to dynamically change or add/remove completely new data and legends to the chart to reflect dynamically generated data which is not know in advance. As I understand it, Open TBS does not allow us to dynamically generate  new charts from scratch so what you have to do is create a chart in Word then modify it using PlugIn(OPENTBS_CHART, $chartName, '1', $newValues, false) etc. I have created a pie chart with 2 legends and related data and I am trying to change the legends and related data to reflect new data. The data is being pulled from a database so I don't know the new legends in advance so it will be completely dynamic. I am getting the following error:

TinyButStrong Error OpenTBS Plugin: (ChartChangeSeries) 'Employee Feedback 1' : unable change series '2' in the chart 'Employee Feedback 1' : Number of the series not found. The process is ending, unless you set NoErr property to true.
DEBUG info for chart:
  - name: 'chart3', title: 'Employee Feedback 1'
AND
- name: 'chart3' , number of series: 1

There must be a specific way of doing this if it is possible?? I have tried various things like looping through data and calling  PlugIn(OPENTBS_CHART... for each legend whilst using the $newLegend parameter, feeding it a manner of different data structures etc but without any success. See below:

$newValues = array('Yes - I now know the process' => 50, 'No - I am still unsure' => 25);
foreach ($newValues as $key=>$val){
            $this->TBS->PlugIn(OPENTBS_CHART, $chartName, 1, $newValues, $key);
        }

So the initial 2 legends could be anything and we want to end up with the legends being the keys of the array above.

I may be failing to understand something fundamental about the process. Also what is meant by 'series' I've read the docs but find anything which gives an explanation.

Thanks
By: Skrol29
Date: 2017-03-13
Time: 23:17

Re: Dynamically changing or adding/removing legends and related data in charts

Hi,

Pie chart are merged correctly when the data are no "switched". When data are not switched, then a click on the "select data" button will display a dialog box with only one item in the list "Legend Entries (series)" and all the captions in "Horizontal (Category) Axis Label".

Can you try a command OPENTBS_CHART_INFO on this chart ?
By: Jonathan Hill
Date: 2017-03-15
Time: 10:15

Re: Dynamically changing or adding/removing legends and related data in charts

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => Yes - I now know the process
                    [1] => No - I am still unsure
                )

            [1] => Array
                (
                    [0] => 2
                    [1] => 0
                )

        )

)

That is the output of OPENTBS_CHART_INFO on the chart. I want to be able to keep the structure but change the legend and data. I'm not sure how the code would differ from the code I've used in the first post.
By: Jonathan Hill
Date: 2017-03-15
Time: 11:24

Re: Dynamically changing or adding/removing legends and related data in charts

I've tried feeding it the same array structure as outputted by OPENTBS_CHART_INFO i.e

$newValues = array(array('A new Legend', 'Another New Legend'), array(2, 11));
        $this->TBS->PlugIn(OPENTBS_CHART, $chartName, '3', $newValues, false);

And I get the error "TinyButStrong Error OpenTBS Plugin: (ChartChangeSeries) 'chart3' : unable change series '1' in the chart 'chart3' : Number of the series not found. The process is ending, unless you set NoErr property to true."

Not sure if or how you can achieve what I'm trying to do.
By: Skrol29
Date: 2017-03-15
Time: 22:06

Re: Dynamically changing or adding/removing legends and related data in charts

Hi,

Is is possible to send your template to me ?
By: Jonathan Hill
Date: 2017-03-20
Time: 17:05

Re: Dynamically changing or adding/removing legends and related data in charts

So I think what I'm asking is can I change existing legends or at least add new ones and remove existing ones. I think the answer is no as per http://www.tinybutstrong.com/forum.php?thr=3012

Correct me if I'm wrong.