From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Simultaneous refresh multi plot( wpf graph)

Solved!
Go to solution

How to use several plot append data simultaneously?

For example, there are 18 plots for Graph. The datasouce of Graph is ChartCollection<Point>[18] graphds

It must execute 18 times of APPEND to update the whole Graph.

Code:

Aps[0-17]=graphds[0-17].append

Dispatcher.BeginInvoke(aps, simulatedData),//executing 18 times

I hope there is a similar data to

graphds.append(Point[18] datasources)

that can refresh 18 plot data at one time.

 

full code in testmultiplot.zip

 

thank you 

0 Kudos
Message 1 of 4
(3,121 Views)

There is nothing special about the delegate created from graphds[i].Append in your code. The WPF dispatcher can accept any delegate. For example, here is a helper delegate for appending to multiple charts:


    Action<ChartCollection<Point>[], IList<Point>[]> AppendAll = ( charts, points ) => {
        for( int i = 0; i < charts.Length; ++i ) {
            charts[i].Append( points[i] );
        }
    };


In your DataWorkerThread method, you can replace the existing aps collection with a var points = new IList<Point>[graphds.Length]; collection, and call the delegate like so:


    while( true ) {
        for( int f = 0; f < graphds.Length; f++ ) {
            IList<Point> simulatedData = new List<Point>( );
            // ...
            for( int i = 0; i < cyclecountper; i++, x++ ) {
                // ...
            }

            // Save the simulated data for the current chart.
            points[f] = simulatedData;

            //...
        }

        // Dispatch all the work with a single call at the end.
        this.Dispatcher.BeginInvoke( AppendAll, graphds, points );

        //...
    }

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

Thank you but

I hope DATASOURCE is ChartCollection<CustomClass> ps, not ChartCollection<Point> [] ps .datasource not array

0 Kudos
Message 3 of 4
(3,081 Views)
Solution
Accepted by topic author jiewei_li

The specific item types involved are not importent. The idea of the AppendAll helper function is just to have a single method to perform all of the append work, rather than invoking for each separate append. You could also define the helper generically and use any data type for the items:


    private static void AppendAll<T>( ChartCollection<T>[] charts, IList<T>[] values ) {
        for( int i = 0; i < charts.Length; ++i ) {
            charts[i].Append( values[i] );
        }
    }

~ Paul H
0 Kudos
Message 4 of 4
(3,039 Views)