I showed a simple code so I could show my problem.
According to the code, it takes about 15 milliseconds when I add the first bar to BarSeries in chart.
But by adding more bar to BarSeries , this time increases so that when adding the 200th bar to BarSeries, this time increases to 190 milliseconds.
If I clear the series at this point, this time will be reduced again.
How can I keep this processing time constant? Because in large projects, this time increases so much that at some point the software hangs.
..........................................................................................................
LightningChart _chart;
Timer Timer_GenerateBar;
Label ProceccTime;
int sum_value;
public MainWindow()
{
InitializeComponent();
CreateChart();
}
public void CreateChart()
{
_chart = new LightningChart();
_chart.ViewXY.BarViewOptions.Grouping = BarsGrouping.ByLocation;
_chart.ViewXY.BarViewOptions.Stacking = BarsStacking.Stack;
_chart.ViewXY.BarViewOptions.Orientation = BarsOrientation.Horizontal;
_chart.BeginUpdate();
_chart.ViewXY.XAxes[0].SetRange(0, 200);
_chart.ViewXY.YAxes[0].SetRange(0, 10);
_chart.ViewXY.LegendBoxes[0].Visible = false;
_chart.EndUpdate();
grid1.Children.Add(_chart);
ProceccTime = new Label();
ProceccTime.Height = 50;
ProceccTime.Width = 150;
ProceccTime.Foreground = Brushes.Yellow;
ProceccTime.FontSize = 22;
grid1.Children.Add(ProceccTime);
Timer_GenerateBar = new Timer(GenerateBar, null, 2000, Timeout.Infinite);
}
public void GenerateBar(object state)
{
_chart.Dispatcher.Invoke(() =>
{
var watch = System.Diagnostics.Stopwatch.StartNew();
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_chart.BeginUpdate();
sum_value++;
if (sum_value >= 200)
{
_chart.ViewXY.BarSeries.Clear();
sum_value = 5;
}
BarSeriesValue[] data = new BarSeriesValue[1];
data[0].Value = 1;
data[0].Location = 7;
BarSeries bar = new BarSeries();
bar.Fill.Color = Colors.Red;
bar.Fill.GradientColor = Colors.Red;
bar.Values = data;
_chart.ViewXY.BarSeries.Add(bar);
_chart.EndUpdate();
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
watch.Stop();
ProceccTime.Content = watch.ElapsedMilliseconds.ToString();
});
Timer_GenerateBar.Change(500, Timeout.Infinite);
}
Increase processing time by adding bar to BarSeries in stack mode
Moderator: Queue Moderators
-
- Posts: 4
- Joined: Mon Aug 06, 2018 4:14 pm
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: Increase processing time by adding bar to BarSeries in stack mode
For the best performance try using minimal amount of Series. That is, instead of creating new series for each new value/bar, you should add item in array of barSeries.Values. You can do it with AddValue(…) or SetValue(…) methods.
Check User's Manual for more description and investigate real-time example from our Demo, ExampleBarsXY.
If you have many bars, then simple bars (and far more optimally) could be created with LineCollection.
Hope this helps.
Check User's Manual for more description and investigate real-time example from our Demo, ExampleBarsXY.
If you have many bars, then simple bars (and far more optimally) could be created with LineCollection.
Hope this helps.