In This Topic
Nevron Chart for .NET contains several series types that are specifically optimized for the display of large amounts of data using the GPU. These series are referred to as Fast Series in the documentation. The Fast Series currently include the NFastBarSeries, NFastLineSeries, NFastPointSeries, and the different surface series types.
The common in those series is the way data is organized and stored in memory to facilitate efficient rendering on the GPU. The data of the Fast Series is organized in memory blocks that have one or more data channels. The data for those channels is stored interleaved in the chart memory. The following picture shows how some sample data for a series containing three data points with XY values and a color per data point is stored in memory:
The rest of this topic will teach you how to add data to a fast series.
Adding Data With Managed Code
The different fast series have several methods that allow you to add data to the series using managed code. These functions usually contain the name of the data channel and the data to add to this data channel for a specific data point index. For example SetValue will modify the Y value at the specified index, whereas SetXValue will modify the X value respectively.
Fast series have only Y value channel by default. You need to enable the X value and Color channels if you want to specify custom X Values and Color per data point. This is done using the UseXValues and UseColors properties of the series data.
The following code snippet adds several data points to a fast line series with custom color per data point:
C# |
Copy Code
|
NFastLineSeries fastLineSeries = new NFastLineSeries();
chart.Series.Add(fastLineSeries);
fastLineSeries.Data.UseXValues = true;
fastLineSeries.Data.UseColors = true;
fastLineSeries.Data.SetCount(3);
fastLineSeries.Data.SetXYValue(0, 0, 0);
fastLineSeries.Data.SetXYValue(1, 1, 1);
fastLineSeries.Data.SetXYValue(2, 2, 2);
fastLineSeries.Data.SetColor(0, Color.Red);
fastLineSeries.Data.SetColor(1, Color.Green);
fastLineSeries.Data.SetColor(2, Color.Blue);
|
Adding Data Using Unmanaged Code
You can also add data to fast series by directly manipulating the data channels contained in its memory block. This involves using unmanaged code so your application must have "Allow Unsafe Code" checked in the project build settings. The following code shows how to add the same data as in the previuos example to a fast line series but this time using unamaged code:
C# |
Copy Code
|
NFastLineSeries fastLineSeries = new NFastLineSeries();
chart.Series.Add(fastLineSeries);
fastLineSeries.Data.UseXValues = true;
fastLineSeries.Data.UseColors = true;
fastLineSeries.Data.SetCount(3);
unsafe
{
fixed (byte* pData = &fastLineSeries.Data.Data[0])
{
int dataItemSize = fastLineSeries.Data.DataItemSize;
float* pXValues = (float*)fastLineSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.XValueF, pData);
float* pYValues = (float*)fastLineSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.YValueF, pData);
uint* pColors = (uint*)fastLineSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.Color, pData);
// add x values
*pXValues = 0;
pXValues += dataItemSize;
*pXValues = 1;
pXValues += dataItemSize;
*pXValues = 2;
pXValues += dataItemSize;
// add y values
*pYValues = 0;
pYValues += dataItemSize;
*pYValues = 1;
pYValues += dataItemSize;
*pYValues = 2;
pYValues += dataItemSize;
// add colors
*pColors = 0xFF0000FF;
pColors += dataItemSize;
*pColors = 0xFF00FF00;
pColors += dataItemSize;
*pColors = 0xFFFF0000;
pColors += dataItemSize;
}
}
fastLineSeries.Data.OnDataChanged();
|
You need to call OnDataChanged after you've finished passing data.
Shader Rendering
All fast series rendering by default is performed using OpenGL shaders. This means that logical to view coordinate treansformations, colors, normals, lighting effects, etc. are performed through a custom vertex, geometry and fragment pipeline. This offloads the CPU from many calculations and is in most cases faster that normal rendering in which the control uses the fixed OpenGL pipeline. In cases when you want to revert to the fixed pipeline you can turn off shader rendering using:
C# |
Copy Code
|
someFastSeries.EnableShaderRendering = false; |
See Also