Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make the CNiGraph Y axis for time print only ticks on even 15 seconds.

I use the CNiGraph y axis for time. The user wants only time printed out every 15 seconds, ie, 12:10:00, 12:10:15, 12:10:30, etc.

The time on the y axis changes every second. Currently the time tics move up the graph (scrolls up) with their repective times. This is good and I need to have this moving effect.
0 Kudos
Message 1 of 6
(4,744 Views)
You can display date/time formats in the Y axis by setting the CNiAxis::FormatString property to a format that displays dates/times and then use the COleDateTime class to handle converting the date/time to a double. COleDateTime encapsulates time stored as a DATE, which is a typedef for double. COleDateTime uses the same conversion factor for date/time as what the axis expects, so you can use COleDateTime to configure your date/time data, then the conversion operator to DATE, which is really a double, will handle the conversion when you assign it to the appropriate properties on the axis.

For example, create a new project, add a graph to the dialog, add a member variable for the graph called m_graph, add a button to the dialog, and add a click event handler
for the button. Add this code to the click event handler:

CNiAxis yAxis = m_graph.Axes.Item(2);

COleDateTime now = COleDateTime::GetCurrentTime();
COleDateTime minTime(now.GetYear(), now.GetMonth(), now.GetDay(), 12, 0, 0);
COleDateTime maxTime(now.GetYear(), now.GetMonth(), now.GetDay(), 12, 1, 0);
COleDateTime minTimePlus15(now.GetYear(), now.GetMonth(), now.GetDay(), 0, 0, 15);
COleDateTime interval = minTimePlus15 - minTime;

yAxis.FormatString = _T("hh:nn:ss");
yAxis.Ticks.AutoDivisions = false;
yAxis.Ticks.MajorDivisions = 4;
yAxis.Discrete = true;
yAxis.Minimum = minTime;
yAxis.Maximum = maxTime;
yAxis.DiscreteBase = minTime;
yAxis.DiscreteInterval = interval;

Run the application, click the button, and you'll see that after clicking the button the axis will display tick labels for 12:00:00, 12:00:15, etc. Hope this helps.

- Elton
0 Kudos
Message 2 of 6
(4,746 Views)
I've got a similar problem. I use the x-axis for time and the y-axis for a value in dB.

Every 10 seconds I get a value for the graph, but using "graphname.Plots.Item("Plot-1").ChartY(value);" it is not charted at all.

But this only happens when I'am using a date/time formatstring, if i use plain numbers for the x-axis it works fine.

I've tried to set the minimum to now, but i'm not sure if the values are beeing charted from now or still from 0.

Do i have to use the ChartY function which takes a xInc parameter and set it to 10 seconds?

I'm really stuck and would be happy about any tips.

thanks in advance



0 Kudos
Message 3 of 6
(4,565 Views)
Hi norsonic,

I would expect that if you gave the xInc parameter a value that corresponded with the date/time format you are trying to use, that it would add the data appropriately.
Although we don't typically take on code, if you'd like to post a small example that demonstrates the problem I'd be happy to take a look at it and see if there's something we can do to fix it.

Let me know norsonic, have a good one.
Dan Weiland
0 Kudos
Message 4 of 6
(4,539 Views)
Some initializing code (made with the help given earlier in this thread):

        COleDateTime tmpOleTime[2];
        COleDateTimeSpan tmpOleTmSpan(0,1,0,0);
        COleDateTime interval(0, 0, 0, 0, 10, 0);

        tmpOleTime[0] = tmpOleTime[1] = GetDocument()->m_tTime.GetTime(); //initial time for the first value
        tmpOleTime[1] = tmpOleTime[1] + tmpOleTmSpan;

        m_graphLeq1h.Axes.Item("XAxis").FormatString = _T("hh:nn:ss");
        m_graphLeq1h.Axes.Item("XAxis").Ticks.AutoDivisions = false;
        m_graphLeq1h.Axes.Item("XAxis").Ticks.MajorDivisions = 4;
        m_graphLeq1h.Axes.Item("XAxis").Discrete = true;
        m_graphLeq1h.Axes.Item("XAxis").Minimum = tmpOleTime[0].m_dt;
        m_graphLeq1h.Axes.Item("XAxis").Maximum = tmpOleTime[1].m_dt;
        m_graphLeq1h.Axes.Item("XAxis").DiscreteBase = tmpOleTime[0].m_dt;
        m_graphLeq1h.Axes.Item("XAxis").DiscreteInterval = interval;

        double tenminutes = 0.0069444;

        double dvalue = 0.0;

        dvalue = tmpOleTime[0].m_dt;


        /* this is for testing purpose to add some testdata */
        for(int ix = 1; ix < 6; ix++)
        {
            m_graphLeq1h.Plots.Item("Plot-1").ChartXY(dvalue, 30 + ix * 10);
            dvalue = tmpOleTime[0].m_dt + tenmin;
        }
        /*but this doesnt add anything to the graph */

To add the real data i would use this function:

    m_graphLeq1h.Plots.Item("Plot-1").ChartY(doc->m_tmpLEQVector, 0.0069444);



0 Kudos
Message 5 of 6
(4,531 Views)
Hi Norsonic,

Could you just post your actual project, or if that's not possible, a simple example project that recreates the behavior? I want to make sure I'm not missing something.

Thanks
Dan Weiland
0 Kudos
Message 6 of 6
(4,498 Views)