Remove Trace from Plot in JavaScript
How to remove a trace from a plot in JavaScript with D3.js.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.
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);
};
