Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph.DefaultPlotRenderers.ReplaceAll() does not cause any changes to GUI

Solved!
Go to solution

WPF C#

 

Hi,

I have no idea what I am doing differenly from DefaultPlotRenderers example that came with NI Studio.  I can see in debugger that DefaultPlotRenderers object contains either nothing or my custom settings (based on option I select).  This matches how it looks in debugger in the example from NI.

Here's my code and any help would be greately appreciated.

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using NationalInstruments.Controls;
using NationalInstruments.Controls.Primitives;
using NationalInstruments.Controls.Rendering;

namespace FireflyMmwDiagnostics
{
    public partial class GraphLinear : Window, INotifyPropertyChanged
    {
        private bool m_includeMarkers = true;
        public bool IncludeMarkers
        {
            get { return m_includeMarkers; }
            set { m_includeMarkers = value; OnPropertyChanged("IncludeMarkers"); }
        }

        public virtual event PropertyChangedEventHandler PropertyChanged;
        public virtual void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
private readonly PlotRendererCollection PlotRendererCollectionWithMarkers = new PlotRendererCollection(); public GraphLinear() { InitializeComponent(); DataContext = this; } public void AddData<T>(List<T[]> data) { T[,] arrayData = new T[data.Count, data[0].Length]; for (int plot = 0; plot < data.Count; plot++) { // Create plot object AddPlotToGraph(data[plot].Length, ""); // Convert list to array for (int point = 0; point < data[plot].Length; point++) arrayData[plot, point] = data[plot][point]; } // Assign data Graph.DataSource = arrayData; } private void AddPlotToGraph(int dataSize, string label) { Brush brush = Utility.RandomBrush(); ChartCollection<double, double> chartCollection = new ChartCollection<double, double>(dataSize); Plot plot = new Plot(label); LinePlotRenderer linePlotRenderer = new LinePlotRenderer() { Stroke = brush, StrokeThickness = 2}; LinePlotRenderer linePlotRenderer2 = new LinePlotRenderer() { Stroke = brush, StrokeThickness = 8 }; PlotRendererCollectionWithMarkers.Add(linePlotRenderer2); // Store away alternating plot setting plot.Renderer = linePlotRenderer; Graph.Plots.Add(plot); } private void CheckBoxIncludeMarkers_Click(object sender, RoutedEventArgs e) { if (IncludeMarkers) Graph.DefaultPlotRenderers.ReplaceAll(PlotRendererCollectionWithMarkers); else Graph.DefaultPlotRenderers.Clear(); }

 

     // This is a snippet from other class where I make a call to show this graph...           

GraphLinear graphLinear = new GraphLinear(); graphLinear.AddData(listOfSmaData); graphLinear.Show();

 

 

0 Kudos
Message 1 of 4
(4,238 Views)

In your AddPlotToGraph method, you are explicitly assigning the Renderer of the new plot (plot.Renderer = linePlotRenderer;). A locally assigned renderer always takes precedence over the default renderer in the DefaultPlotRenderers collection.

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

Ah, I see... I just verified this.

So what's the best way to toggle my own custom plot settings?

 

Just by traversing through custom list of PlotRendererGroup based on my option?

Something like this

 

Graph.Plots[plotIndex].Renderer = ListOfPlotRendererGroups[plotIndex];

 

Thanks!

0 Kudos
Message 3 of 4
(4,222 Views)
Solution
Accepted by kirko7

If you need the plot renderer to be set, then manually updating the renderers on all plots would be the way to go.

 

If you leave the plot renderer unset, you could toggle between two default plot renderer collections (i.e. save both linePlotRenderer and linePlotRenderer2 into collections, and in the check box handler update with one collection or the other).

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