Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

IntensityGraph Custom Horizontal Axis

Solved!
Go to solution

Hi,

      I am using the IntensityGraph in WPF and have the following problem:

      - The horizontal axis is time and I want it to be from 0 to X seconds (say 5, for example).

      - I want to update the graph every 0.2 seconds. 

      - When I reach the end of the graph I want it to roll over or scroll, so I need to remove some of the old points and replace them with new ones. 

      My question is:

      How to configure the IntensityGraph and how to add data to the DataSource such that on the X axis I have 25 data points and the labels remain from 0 to 5 as initially set. In my attempts, I had the X axis display all labels form 0 to 25 or I could only display 5 points (setting the range 0,5 I see labels 1 to 5 and only 5 points). 

 

     Any example would be helpful.

 

Thank you,
Cosmin. 

 

0 Kudos
Message 1 of 4
(2,938 Views)

Hey Cosmin, 

 

I found this short example online. I hope it'll help you to get started on your project.

How to: Plot and Chart with the Measurement Studio WPF Intensity Graph Control

 

 Cheers,

Saki K.
Applications Engineer
0 Kudos
Message 2 of 4
(2,895 Views)
Solution
Accepted by Cosmin.Serban

Hi Saki,

     I knew about the example, but to solve my original problem I needed to resort to using a Point3D matrix. This gives the flexibility to define the granularity of the X axis.

    However, I find it hard to configure the behavior I want via Binding in WPF. I found other examples using a ChartCollection of doubles, perhaps I can change the type to Point3D and see how it goes.

 

Thank you for looking into this!

Cosmin. 

     

0 Kudos
Message 3 of 4
(2,889 Views)

Using a 2D array of Point3D will work fine for your case. Depending on what you meant by "roll over or scroll" behavior in your original question, using a chart collection with explicit X values may make more sense:


    public partial class MainWindow : Window {
        private const double Interval = 0.2;
        private readonly DispatcherTimer timer;
        private readonly ChartCollection<double, double[]> chart
                   = new ChartCollection<double, double[]>( capacity: 25 );

        public MainWindow( ) {
            InitializeComponent( );

            // Initialize chart with data.
            chart.Append( 0, new double[0] );

            // Tell graph about data, and interval.
            graph.DefaultHorizontalInterval = Interval;
            graph.DataSource = chart;

            // Use a timer to update chart data.
            timer = new DispatcherTimer( TimeSpan.FromSeconds( 0.1 ), DispatcherPriority.Normal, OnTimerTick, Dispatcher );
        }

        private void OnTimerTick( object sender, EventArgs e ) {
            // Add a new set of data after the previous point (changing value length to make updates more obvious).
            var previous = chart[chart.Count - 1];
            double x = previous.Index + Interval;
            double[] y = Enumerable.Repeat( x * 2.0, previous.Value.Length % 2 + 1 ).Select( ( v, i ) => v + i ).ToArray( );
            chart.Append( x, y );
        }
    }

~ Paul H
0 Kudos
Message 4 of 4
(2,868 Views)