11-11-2008 03:11 PM
I am plotting with a scattergraph. I am reading data from a database plotting it with PlotXYAppend. However, on my graph, I also need to insert limit lines, which are also read from a database. The channel data (y-axis) is versed my time (x-axis) which continues to change. I need my limit lines to be seperate from channel plot and to remain on the graph as the time changes on the x-axis. I am very new to C# and using Measurement Studio. I have code...
private void _Timer_Tick(object sender, EventArgs e)
{
double xValue = (double)NationalInstruments.DataConverter.Convert(DateTime.Now.TimeOfDay, typeof(double));
double yValue = 0.0;
//double lastXValue = 0.0;
//double lastYValue = 0.0;
//Plot1
if (_plot1 != null)
{
foreach (Item item in _plot1.Items)
{
yValue = _getter.GetChannel(ch.ID).CurrentValue();
foreach (Table table in _plot1.Tables)
{
_getter.GetTable(table.ID);
foreach (TableData ltd in lookup.TableData)
{
//PLOTTING LIMIT LINES
double ltdXValue = ltd.X;
double ltdYValue = ltd.Y;
scatterPlot1.LineColor = Color.Red;
scatterPlot1.PointColor = Color.Pink;
scatterPlot1.PointStyle = PointStyle.SolidTriangleRight;
scatterPlot1.PlotXY(ltdXValue, ltdYValue);
}
}
//Plotting DATA
this.scatterPlot1.PointStyle = PointStyle.SolidDiamond;
this.scatterPlot1.PointColor = Color.Lime;
this.scatterPlot1.LineColor = Color.Yellow;
scatterPlot1.PlotXYAppend(xValue, yValue);
}
Also, for my time I am getting a number like 535330 (double xValue = (double)NationalInstruments.DataConverter.Convert(DateTime.Now.TimeOfDay, typeof(double))). How do I get the current timestamp? Thanks in Advance!
11-11-2008 05:30 PM
Hello,
One way to accomplish this would be to create a new plot object, and add it to the ScatterGraph's collection of plots. Also, to get your X Axis to display the time instead of those large double values, you need to create a format string for the X Axis labels. I have simplified your code a little bit, and these changes can be seen below:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Assign a format string to the axis label
scatterGraph1.XAxes[0].MajorDivisions.LabelFormat = new FormatString(FormatStringMode.DateTime, "hh:mm:ss");
}
private void timer1_Tick(object sender, EventArgs e)
{
Double limitVal = 6.5;
Random rand = new Random();
// Create new plot
ScatterPlot limitPlot = new ScatterPlot();
// Add new plot to Graph collection
scatterGraph1.Plots.Add(limitPlot);
//PLOTTING LIMIT LINES
limitPlot.LineColor = Color.Red;
limitPlot.PointColor = Color.Pink;
limitPlot.PointStyle = PointStyle.SolidTriangleRight;
limitPlot.PlotXY(DataConverter.Convert<Double>(DateTime.Now.TimeOfDay), limitVal);
//Plotting DATA
this.scatterPlot1.PointStyle = PointStyle.SolidDiamond;
this.scatterPlot1.PointColor = Color.Lime;
this.scatterPlot1.LineColor = Color.Yellow;
scatterPlot1.PlotXYAppend(DataConverter.Convert<Double>(DateTime.Now.TimeOfDay), rand.NextDouble()*10);
}
}
Let me know if I've misunderstood what you were asking for, or if I can help you with anything else!
NickB
National Instruments
11-12-2008 09:07 AM
Thanks NickB,
I'm just in and will test the code, immediately. I'll let you know how it goes! THANKS!
11-13-2008 01:16 PM
Nick,
I think your suggestion will work, however, I'm still working on it.
Another thing, I have the correct time stamp when the plot is Channel vs. Time, but when I need it to be Channel vs. Channel, my x-axis is still a time stamp, when I need a range of numbers. Please help.
11-13-2008 02:46 PM
I have not a clue as to edit a recent post...Sorry...
Another question, how do I get my scattergraph to format automatically. For instance, what if my limit lines are at a point of 1 and 50,000 on the y-axis, and my other points are only at 86. And my database has it where it sets the range for the x and y-axes. For the points that are out of my range, how do I get to see the full graph with all the points plotted.