Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot remove the legend even after removing the graph #49

Closed
debsush opened this issue Jun 25, 2016 · 2 comments
Closed

Cannot remove the legend even after removing the graph #49

debsush opened this issue Jun 25, 2016 · 2 comments

Comments

@debsush
Copy link

debsush commented Jun 25, 2016

Hi,

Suppose I have a data on 5 stocks in amStockChart. The first stock data is in dataSets[0] and the remaining 4 stocks to be compared are in dataSets[1]
I want to allow the users to remove any of the 4 comparing stocks. Based on users choice of stock to be removed, a script re-runs the data and removes a particular stock of user's choice from the 4-stock data and then passes this new data of 3 stocks (called NewData) and the graph ID of the graph to be removed to a JavaScript function.

JavaScript Function does the following:

  chart.dataSets[1].dataProvider= NewData;
  chart.validateData();

    for (i = 0; i < chart.panels[0].graphs.length; i++) {
        if (chart.panels[0].graphs[i].id == GraphID) {
           chart.panels[0].graphs.splice(i, 1);
           chart.panels[0].graphs.splice(i+1, 1);
        }
    }

          //var graph = chart.panels[0].getGraphById(GraphID);
          //chart.panels[0].removeGraph(graph);
          //graph1 = chart.panels[0].getGraphById('comparedGraph_'+GraphID+'_ds2');
          //chart.panels[0].removeGraph(graph1);


The problem with the above is that the graph gets removed but the legend remains. Please see screenshot below:

image

Please let me know where am I going wrong

@martynasma
Copy link
Collaborator

Wouldn't it be more efficient to define several data sets instead and switch between them instead of updating the actual data?

@debsush
Copy link
Author

debsush commented Jun 27, 2016

Hi,

In general yes, your suggestion is apt and very useful. In my particular case, the project requires the different approach. I am using the below now and it is working fine

var graphcnt = chart.panels[0].graphs.length;
for (i = 0; i < graphcnt; i++) {
if (chart.panels[0].graphs[i].id == params[3]) {
var graph = chart.panels[0].graphs[i];
chart.panels[0].removeStockGraph(graph);
var graph = chart.panels[0].graphs[i+1]; //this is to remove the compare graph
chart.panels[0].removeStockGraph(graph);
}
chart.dataSets[1].dataProvider= NewData;
chart.validateData();

Please let me know in case I am not following the best practices.

Regards,
SD

@debsush debsush closed this as completed Jun 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants