Nevron Forum

Prevent graph update while adding data

https://www.nevron.com/Forum/Topic8546.aspx

By Joël Golinucci - Wednesday, April 9, 2014

Hi,

I would like to know what is the best way to update a large quantity of NRangeSeries into a graph without freezing the whole application.
Knowing that the graph will be updated every 5 seconds (maybe less)

I thought of 2 options :

1) Disable the graph refresh, clear all values from the graph, add the new values and fillstyles, re-enable the graph refresh
2) As the points will be the same each time but only the colors will change, only update the fill styles


For option 1, I'm a bit lost between all these nevron objects and I don't really know where to look for the refresh disable/enable property (the NChartControl, the NChart or the NRangeSeries object) ?

For option 2, I'm not sure that using the FillStyles is the best thing to do. For each point I would like to be able to define an associated color corresponding to a value not depending on the coordinates. Now each time I add a new point, I do it this way:


For Each pt As tGraphPoint In ptLst
fRangeSeries.Values.Add(pt.Z) 'Nevron Y start - Deepth (Z axis)
fRangeSeries.Y2Values.Add(pt.Z + 2) 'Nevron Y end
fRangeSeries.XValues.Add(pt.X) 'Nevron X start - Horizontal (X axis)
fRangeSeries.X2Values.Add(pt.X + 1) 'Nevron X end
fRangeSeries.ZValues.Add(pt.Y) 'Nevron Z start - Vertical (Y axis)
fRangeSeries.Z2Values.Add(pt.Y + 1) 'Nevron Z end
i += 1
fRangeSeries.FillStyles.Add(i, New NColorFillStyle(GetColorFromValue(pt.Value, plotVariable)))
Next


But when comes the time to refresh what is the best thing to do ? Clear FillStyles and only add the new ones or is there a way to replace the specific color for a given coordinate ?

Thanks for your help,
Regards,

Joël
By Nevron Support - Thursday, April 10, 2014

Hi Joel,

1. In order to turn off automatic refresh you only need to write:

nChartControl1.AutoRefresh = false;

Adding values is achieved most efficiently when you use the AddRange method - for example:

rangeSeries.Values.Clear();
rangeSeries.Values.AddRange(values);

where values in this case is a double[] array. Same applies for fill styles.

2. You can update the colors in the fill style using code similar to:

int count = rangeSeries.FillStyles.Count;
for (int i = 0; i < count; i++)
{
NColorFillStyle colorFill = rangeSeries.FillStyles[i] as NColorFillStyle;

if (colorFill != null)
{
colorFill.Color = someNewColor;
}
}

This will be more efficient that using new in order to update each new fill style.

Let us know if you meet any problems or have any questions.