-
|
I found myself with a problem harder than I thought: is there a way to remove a point from a plot, without having to rebuild the entire chart? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @dprevato, here are some options you may find useful! I recognize this is a difficult task currently, and making it easier is a high priority task in my triage list #1028 Change Data in Fixed-Length ArraysIf you plot data in fixed-length arrays, you can change the values in the original arrays and request a new render. This is extremely fast. double[] xs = { /* your data */ }
double[] ys = { /* your data */ }
// plot your original data
formsPlot1.plt.AddScatterPlot(xs, ys);
formsPlot1.Render();
// modify the original data arrays and re-render
ys[5] = 123;
formsPlot.Render();ScatterPlotListThis option is best if the number of data points changes often This plot type is implemented as a temporary plot type but it might get you closer to your goal // create the plottable and add it to the plot
var plt = new ScottPlot.Plot();
var spList = new ScottPlot.Plottable.ScatterPlotList();
plt.Add(spList);
// modify elements in the list whenever you want
spList.Add(x, y);The limitation here is that I implemented ScottPlot/src/ScottPlot/Plottable/ScatterPlotList.cs Lines 46 to 78 in 729388b MinRenderIndex and MaxRenderIndexUse min/max render index fields to limit points displayed at the edge This option is best if data points are added and removed at the start and end of the plot. You can create a plot with a very large array, then just control visibility at the edges. // plot original data
var plt = new ScottPlot.Plot();
var myScatterPlot = plt.AddScatterPlot(xs, ys);
// set the index of the last point to render.
// you can increase this number as the xs and ys array is populated with more data.
myScatterPlot.MaxRenderIndex = 123;Replace ArraysYou could replace the data in the plottable with a new array of a different size when the data changes. // plot original data
var plt = new ScottPlot.Plot();
var myScatterPlot = plt.AddScatterPlot(xs, ys);
// plot new data of a different size
myScatterPlot.Update(newXs, newYs);Clear and ReplotThis is the most extreme example, but it works // plot original data
var plt = new ScottPlot.Plot();
plt.AddScatterPlot(xs, ys);
// plot new data of a different size
plt.Clear();
plt.AddScatterPlot(newXs, newYs); |
Beta Was this translation helpful? Give feedback.
-
|
As always, thank you very much for your quick and thorough reply. I ended up choosing the Update method, because in my project the charts are interactive, and the user can change the Y value of any point, or apply offsets to groups of points of his choice, or, most importantly, remove one or more points altogether. The first two cases do not present difficulties, as the total number of points does not change; and now, thanks to Update :) the deletion is also very fast like everything in your fantastic library :) |
Beta Was this translation helpful? Give feedback.
Hi @dprevato, here are some options you may find useful!
I recognize this is a difficult task currently, and making it easier is a high priority task in my triage list #1028
Change Data in Fixed-Length Arrays
If you plot data in fixed-length arrays, you can change the values in the original arrays and request a new render. This is extremely fast.
ScatterPlotList
This option is best if the number of data points changes often
This plot type is implemented …