Remove Trace from Plot in JavaScript
How to remove a trace from a plot in JavaScript with D3.js.
Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.
function plotGraph(){
var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter',
line: {
color: 'rgb(55, 128, 191)',
}
};
var trace2 = {
x: [1, 2, 3, 4],
y: [16, 5, 11, 9],
type: 'scatter',
line: {
color: 'rgb(255,140,0)',
}
};
var layout = {
title: {text: 'Click Buttons to Delete Traces'},
showlegend:false
};
var data = [trace1, trace2];
Plotly.newPlot('myDiv', data, layout);
}
function deleteTrace(divId){
Plotly.deleteTraces('myDiv', 0);
};