Skip to content

Instantly share code, notes, and snippets.

@vrdriver
Created September 11, 2020 13:41
Show Gist options
  • Save vrdriver/f90715afb15888fa308ca591ea8f33e1 to your computer and use it in GitHub Desktop.
Save vrdriver/f90715afb15888fa308ca591ea8f33e1 to your computer and use it in GitHub Desktop.
// Finding the integer values of a plottable for ScottPlot when you know the name/label of it
// For use with https://github.com/swharden/ScottPlot
formsPlot1.plt.PlotVLine(label: "green", lineWidth: 3, x: position, draggable: true, dragLimitLower: 0, dragLimitUpper: Global.samples[filename_value]);
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment