Reputation: 1518
I have multiple checkboxes to plot data in to my plotly chart. I want to delete traces from chart when unchecked.
<input id="4" type="checkbox" value="radio" onclick="getTraces(this)"/>
<input id="5" type="checkbox" value="micro" onclick="getTraces(this)"/>
getTraces() calls Plotly.addTraces and pass data from Database
Plotly.addTraces[x:[],y:[]] // add traces in to chart
delete Traces is possible with
Plotly.deleteTraces[]// pass the position of the trace to delete trace.
My Problem is i need to pass the position of the trace i want to delete. How can i safe the position of the traces? What i thought is to safe somehow the sequence of my checked checkboxes. If i would know that checkbox one was checked first, then the position of the graph would be also first.
always when i call
Plotly.addTraces[x:[],y:[]]
there is a new element in the data Array of the Plot. like this : data[trace1,trace2,trace3].
Upvotes: 0
Views: 2127
Reputation: 1518
I have found a solution for my answer.
Plotly.addTraces[x:[],y:[],name:"Chart1"] // add traces in to chart
i get the chart by
chart3 = document.getElementById('chart3');
for(var i=0;i<chart3.data.length;i++)
{
if(chart3.data[i]["name"]==nameofCharttodelete)
{
Plotly.deleteTraces('chart3',i);
}
}
i loop through the data array of the chart and compare the name from the chart with my checkbox value.
Upvotes: 1