Getting the value(object/index/properties) of the PlotVLine I just dragged?
See original GitHub issueHow do I get the value(object/index/properties) of the PlotVLine I just dragged, or am presently dragging in either realtime for MouseDown, or on MouseUp?
It would be nice to know what it’s exact location for the xAxis (yet again). I can loop through all of the PlotLines and get the values, but knowing that actual line and addressing it directly would be better.
I have added the following to my code, to know when the mouse is up on the control, but, it doesn’t give me much at all.
public Form1()
{
InitializeComponent();
this.formsPlot1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.formsPlot1_MouseUp);
}
and
private void formsPlot1_MouseUp(object sender, MouseEventArgs e)
{
Console.WriteLine("MouseUp");
Console.WriteLine(sender.ToString());
Console.WriteLine(e.ToString());
// This would be ideal, though it will fail at this present time.
var X = sender.PlotVLine.X;
// ... update values based on X etc
}
This next bit, I realise this may be the wrong, or not the original intended way of doing this, but I couldn’t find any other way… it seems to work for individual elements for a short search, but not at all good for real-time. Basically, it you need to find the index of a known ‘label’.
formsPlot1.plt.PlotVLine(label: "green", lineWidth: 3, x: position, draggable: true, dragLimitLower: 0, dragLimitUpper: 100000);
String plotname = "";
int plottablescount = formsPlot1.plt.GetSettings(false).plottables.Count;
for (int i = 0; i < plottablescount; i++)
{
Console.WriteLine(formsPlot1.plt.GetSettings(false).plottables[i].ToString()); // PlottableVLine (green) at X=516587
Console.WriteLine(formsPlot1.plt.GetSettings(false).plottables[i].GetLegendItems());// ScottPlot.Config.LegendItem[]
Console.WriteLine(formsPlot1.plt.GetSettings(false).plottables[i].GetLimits()); // x1=516587.000, x2=516587.000, y1=NaN, y2=NaN
Console.WriteLine(formsPlot1.plt.GetSettings(false).plottables[i].GetType()); // ScottPlot.PlottableVLine
Console.WriteLine(formsPlot1.plt.GetSettings(false).plottables[i].GetHashCode()); // 2383799
var stringlabel = formsPlot1.plt.GetSettings(false).plottables[i].ToString(); // PlottableVLine (green) at X=516587
Console.WriteLine(Regex.Match(stringlabel, @"\(([^)]*)\)").Groups[1].Value); // This will extract the name of the moveable plotline
plotname = Regex.Match(stringlabel, @"\(([^)]*)\)").Groups[1].Value;
if (plotname == "green")
{
// do stuff as the 'green' label was found
}
}
Thanks again.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
Hey @vrdriver, sorry it took so long for me to get to this but I’m really happy that @StendProg was able to provide an excellent and thorough answer.
To summarize the conclusion about how to continuously read the position of dragged axis lines, the best way is to save the object
PlotVLine()
returns and access itsposition
property whenever you want to know where the line is. Whether reading this property is triggered by a timer or some type of mouse move event is up to you.Regarding the rendering system, ScottPlot uses System.Drawing to draw a plot as a Bitmap. User controls are just thin wrappers that watch the mouse and request next Bitmap whenever something changes. The appearance of animation comes from ScottPlot being pretty fast at drawing this way, but all interactivity is achieved by creating new Bitmaps. On one hand this makes it really easy to use and it’s supported on many systems, but on the other hand adding advanced interactivity requires writing your own control.
I second @StendProg’s recommendation to use PlotSignalCost() for plotting things like audio data. It is so fast, even with millions of samples, that refreshing the whole screen takes very little time.
I think this answers all the questions raised in this thread so I’ll close this issue, but feel free to open it again if more questions pop up! --Scott
@StendProg . Thanks for helping with guiding me the right direction. It has helped a lot.
As I have multiple vplots, I’ve redirected the entire event, which keeps that real-time thing happening and I’m then able to get all of them separately and detect changes.
I’ve included this code for others to discover if required.