Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Plotting on 2y axis graph

I have a CWGraph with 2Y axis style. I would like to plot two individual plots, each one with its own y-axis. I have added a second plot from the properties window and I have assigned Y-axis2 to it. What instructions should I use to plot each set of points for each y-axis. I've tried:

m_graph.Plots.Item(1).ChartXY(time, voltage);
m_graph.Plots.Item(2).ChartXY(time, current);

but when I run the program, nothing appears on the plot window. Thanks in advance.
0 Kudos
Message 1 of 7
(3,754 Views)
Your description sounds like it should work. Could you please post a small test project that demonstrates this behavior? Thanks.

- Elton
0 Kudos
Message 2 of 7
(3,754 Views)
I'm not sure if this is what your asking for, but here's a simple code where my UI only has a start button and a CWGraph with member variable m_graph.
Upon pressing start, I just plot voltage and current vs. time.

Here's the code:

void CTestDlg::OnStart()
{
double time = 0;
double voltage = 2.5;
double current = -10;
for(;;)
{
m_graph.Plots.Item(1).ChartXY(time, voltage);
m_graph.Plots.Item(2).ChartXY(time, current);
time++;
}

}
0 Kudos
Message 3 of 7
(3,754 Views)
Sorry, I should have been more specific. I was asking for the actual project so I could open it on my machine, look at the settings, and run it. You can create a .zip file that contains the project and add an attachment to a post in these forums.

- Elton
0 Kudos
Message 4 of 7
(3,754 Views)
Here's the zip file. Thanks again.
0 Kudos
Message 5 of 7
(3,754 Views)
Looking at your project, there are two issues that I see. The first is this:

for(;;)
{
m_graph.Plots.Item(1).ChartXY(time, voltage);
m_graph.Plots.Item(2).ChartXY(time, current);
time++;
}

This is charting data in a very tight, endless loop. You'll notice that not only is the graph not updating, the entire application is not responding. This is because the application is not getting a chance to process windows messages, hence the UI does not get a chance to update. If you want to chart data continuously like this, you will need to either do it on a timer or pump messages somewhere in your loop so Windows messages can be processed.

We can temporarily work around this problem f
or demonstration purposes by changing the OnStart method like this:

void CTestDlg::OnStart()
{
static double time = 0;
double voltage = 2.5;
double current = -10;
// for(;;)
// {
m_graph.Plots.Item(1).ChartXY(time, voltage);
m_graph.Plots.Item(2).ChartXY(time, current);
time++;
// }
}

The intent of this change is that we can click the Start button and data will be added every time that we click. Now if you run the application, you'll notice that there's only one plot displayed. This is because the Y axes are a fixed scale from 0 to 10, but your plot that's displaying current (the second plot) is charting data that's out of range. You can fix this by either adjusting the fixed range of the Y axis that's associated with the current plot, or you can configure it to auto scale.

Hope this helps.

- Elton
0 Kudos
Message 6 of 7
(3,754 Views)
It worked! Just had to add a Sleep() instruction to slow down the loop. Thanks again!
0 Kudos
Message 7 of 7
(3,754 Views)