Hi Jari,
I perform my real time multi-channel graph as the following. The chart does not seems to be pretty because I am using timer to fire a whole bunch of multi-channel data every 1 second. I am having problem on how to use thread to thread multi-channel data on chart. May be you can have some comment on the following method and point some opinion.
I am using PointLineSeries , SeriesPoint[][] to plot my mulit-channel data on chart.
Firstly, I have a timer, to get data table from a buffer. Inside the data table, it contains 9 channels data, and each channels consist of data size 200~400 (it will be variable length, and the length varies on every timer fired.) And each data, contain two information: Data and Time (As shown in my previous picture in this post)
My 3rd party timer in Main(), the timer is ticked every 1 second:
Code: Select all
m_timerThread = new Multimedia.Timer();
m_timerThread.Mode = TimerMode.Periodic;
m_timerThread.Resolution = 1;
m_timerThread.Period = 1000;
m_timerThread.Tick += new EventHandler(m_timerThread_Tick);
m_timerThread.Start();
I get data table from a buffer per timer ticked:
Code: Select all
void m_timerThread_Tick(object sender, EventArgs e)
{
//receiver.GetTable() will get the a Data Table from buffer
lock (receiver.GetTable())
{
// receiver.GetTable().Count will give the
// information of total channel inside the Data Table
m_iChannelCount = (int)receiver.GetTable().Count;
// channel counter to track the number of channel
// inside the foreach loop
m_iChannel = 0;
// I use SeriesPoint[][] to create a 2D array to fit multi-channel data
SeriesPoint[][] aMultiChannelData = new SeriesPoint[m_iChannelCount][];
// This foreach loop is looped to get data for each of
// the channel inside the Data Table
foreach (var c in receiver.GetTable())
{
var channel = c as ChannelInfo;
var data = channel.GetData();
myList = data.ToList<ChannelValue>();
// Define the data size for each channel
aMultiChannelData[m_iChannel] = new SeriesPoint[data.Length];
// Loop on single channel to copy data from buffer
// into the aMultiChannelData[m_iChannel][i]
for (int i = 0; i < myList.Count; i++)
{
aMultiChannelData[m_iChannel][i].Y = myList[i].Data;
m_dLatestX = m_chart.ViewXY.XAxes[0].DateTimeToAxisValue(myList[i].Time);
aMultiChannelData[m_iChannel][i].X = m_dLatestX;
}
// After finish copying data from buffer into
// aMultiChannelData[m_iChannel][i], channel counter +1
m_iChannel++;
}
m_iChannel = 0; // Reset the channel counter to 0
// I feed all the data into this method and update the chart
FeedMultiDataToChart(aMultiChannelData, m_iChannelCount);
Thread.Sleep(10);
}
}
Here, I update the chart and render all the data inside SeriesPoint[][]
Code: Select all
private void FeedMultiDataToChart(SeriesPoint[][] data, int iChannelCount)
{
m_chart.BeginUpdate();
for (int iChannel = 0; iChannel < iChannelCount; iChannel++)
{
m_chart.ViewXY.PointLineSeries[iChannel].AddPoints(data[iChannel], false);
}
m_dLatestX = m_chart.ViewXY.XAxes[0].DateTimeToAxisValue(DateTime.Now);
m_chart.ViewXY.XAxes[0].ScrollPosition = m_dLatestX;
m_chart.EndUpdate();
}
Picture to show a 1 tick data array: (Note that, not all the data size are the same among the channels, some channel has 500 data size, some channel has 400 data size, and some has data size of 200)
- DataArray using SeriesPoint[][] for 1 tick
- FeedDataArrayIntoMethod.JPG (59.93 KiB) Viewed 57661 times
So, my question is.. how to implement threading to thread multi channel data into chart? Or is there any better idea or tool to render real time chart using lightingChart?