This question is locked. New answers and comments are not allowed.
Hello,
I'm using a RadChart databound to an ObservableCollection that display three simultaneous lines. The ObservableCollection has points added to it at a rate of approximately 30 per second. This works great except for when I enable the ZoomScroll on the chart.
When the ZoomScroll (I've only tested the x-axis) is enabled, the application slows and becomes almost unresponsive. However as the application runs and the RadChart gains more and more points the application becomes more responsive.
I want to know if I'm doing something wrong or if there is some way to fix this issue.
I have mocked up an app that demonstrates this issue successfully. When you start the app the RadToggleButtons on the left hand side are practically unresponsive but you can get them to work with excessive clicking and a little luck. If you let it run for a while the buttons slowly become more responsive.
Here is the code:
XAML:
Code Behind:
AccelerationChartValue.cs:
Thanks in advance for you help,
Shawn
I'm using a RadChart databound to an ObservableCollection that display three simultaneous lines. The ObservableCollection has points added to it at a rate of approximately 30 per second. This works great except for when I enable the ZoomScroll on the chart.
When the ZoomScroll (I've only tested the x-axis) is enabled, the application slows and becomes almost unresponsive. However as the application runs and the RadChart gains more and more points the application becomes more responsive.
I want to know if I'm doing something wrong or if there is some way to fix this issue.
I have mocked up an app that demonstrates this issue successfully. When you start the app the RadToggleButtons on the left hand side are practically unresponsive but you can get them to work with excessive clicking and a little luck. If you let it run for a while the buttons slowly become more responsive.
Here is the code:
XAML:
<
UserControl
x:Class
=
"ZoomScrollTestApp.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
xmlns:ZoomScrollTestApp
=
"clr-namespace:ZoomScrollTestApp"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"Auto"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
Grid
Visibility
=
"Visible"
Grid.Column
=
"1"
>
<
Border
x:Name
=
"brdAcceleration"
>
<
telerik:RadChart
x:Name
=
"chartAcceleration"
Tag
=
"Acceleration"
Margin
=
"-5 2 0 0"
>
<
telerik:RadChart.DefaultView
>
<
telerik:ChartDefaultView
ChartLegendPosition
=
"Top"
>
<
telerik:ChartDefaultView.ChartArea
>
<
telerik:ChartArea
LegendName
=
"legendAcceleration"
EnableAnimations
=
"False"
>
<
telerik:ChartArea.AxisX
>
<
telerik:AxisX
IsDateTime
=
"True"
DefaultLabelFormat
=
"#VAL{HH:mm:ss}"
AutoRange
=
"True"
/>
</
telerik:ChartArea.AxisX
>
<
telerik:ChartArea.AxisY
>
<
telerik:AxisY
AutoRange
=
"True"
/>
</
telerik:ChartArea.AxisY
>
<!--Remove Me!-->
<
telerik:ChartArea.ZoomScrollSettingsX
>
<
telerik:ZoomScrollSettings
ScrollMode
=
"ScrollAndZoom"
MinZoomRange
=
".005"
/>
</
telerik:ChartArea.ZoomScrollSettingsX
>
</
telerik:ChartArea
>
</
telerik:ChartDefaultView.ChartArea
>
<
telerik:ChartDefaultView.ChartLegend
>
<
telerik:ChartLegend
x:Name
=
"legendAcceleration"
Header
=
"Acceleration Test Chart"
/>
</
telerik:ChartDefaultView.ChartLegend
>
<
telerik:ChartDefaultView.ChartTitle
>
<
telerik:ChartTitle
/>
</
telerik:ChartDefaultView.ChartTitle
>
</
telerik:ChartDefaultView
>
</
telerik:RadChart.DefaultView
>
<
telerik:RadChart.SeriesMappings
>
<
telerik:SeriesMapping
x:Name
=
"seriesAccelerationX"
LegendLabel
=
"X"
>
<
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:LineSeriesDefinition
ShowItemLabels
=
"False"
ShowPointMarks
=
"False"
/>
</
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:ItemMapping
FieldName
=
"X"
DataPointMember
=
"YValue"
/>
<
telerik:ItemMapping
FieldName
=
"Date"
DataPointMember
=
"XValue"
/>
</
telerik:SeriesMapping
>
<
telerik:SeriesMapping
x:Name
=
"seriesAccelerationY"
LegendLabel
=
"Y"
>
<
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:LineSeriesDefinition
ShowItemLabels
=
"False"
ShowPointMarks
=
"False"
/>
</
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:ItemMapping
FieldName
=
"Y"
DataPointMember
=
"YValue"
/>
<
telerik:ItemMapping
FieldName
=
"Date"
DataPointMember
=
"XValue"
/>
</
telerik:SeriesMapping
>
<
telerik:SeriesMapping
x:Name
=
"seriesAccelerationZ"
LegendLabel
=
"Z"
>
<
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:LineSeriesDefinition
ShowItemLabels
=
"False"
ShowPointMarks
=
"False"
/>
</
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:ItemMapping
FieldName
=
"Z"
DataPointMember
=
"YValue"
/>
<
telerik:ItemMapping
FieldName
=
"Date"
DataPointMember
=
"XValue"
/>
</
telerik:SeriesMapping
>
</
telerik:RadChart.SeriesMappings
>
</
telerik:RadChart
>
</
Border
>
</
Grid
>
<
Border
BorderThickness
=
"1"
BorderBrush
=
"#22000000"
Background
=
"#66FFFFFF"
Grid.Column
=
"0"
CornerRadius
=
"6"
VerticalAlignment
=
"Top"
>
<
StackPanel
x:Name
=
"spButtons"
Orientation
=
"Vertical"
Margin
=
"5"
>
<
telerik:RadRadioButton
x:Name
=
"btn1"
Content
=
"btn1"
Margin
=
"0 5"
IsChecked
=
"True"
/>
<
telerik:RadRadioButton
x:Name
=
"btn2"
Content
=
"btn2"
/>
<
telerik:RadRadioButton
x:Name
=
"btn3"
Content
=
"btn3"
Margin
=
"0 5"
/>
<
telerik:RadRadioButton
x:Name
=
"btn4"
Content
=
"btn4"
/>
</
StackPanel
>
</
Border
>
</
Grid
>
</
UserControl
>
Code Behind:
using
System;
using
System.Linq;
using
System.Windows.Controls;
using
System.Windows.Threading;
using
System.Collections.ObjectModel;
namespace
ZoomScrollTestApp
{
public
partial
class
MainPage : UserControl
{
DispatcherTimer timer =
new
DispatcherTimer();
private
ObservableCollection<AccelerationChartValue> AccelChartPoints =
new
ObservableCollection<AccelerationChartValue>();
private
double
[] SineBuffer =
new
double
[200];
private
double
[] SquareBuffer =
new
double
[200];
private
double
[] SawBuffer =
new
double
[200];
public
MainPage()
{
InitializeComponent();
this
.chartAcceleration.ItemsSource = AccelChartPoints;
GenerateSine();
GenerateSquare();
GenerateSawtooth();
timer.Interval = TimeSpan.FromMilliseconds(33);
// Approx 30 additions per second
timer.Tick +=
new
EventHandler(AddPoint);
this
.timer.Start();
}
private
void
GenerateSine()
{
int
NumSamples = 200;
double
Frequency = 2;
double
SampleRate = 50;
int
SamplesPerWave = (
int
)(SampleRate / Frequency);
double
RadPerSample = (Math.PI * 2) / (
double
)SamplesPerWave;
double
SinVal = 0;
for
(
int
i = 0; i < NumSamples; i++)
{
SinVal = Math.Sin(RadPerSample * (
double
)(i % SamplesPerWave));
SineBuffer[i] = (Math.Floor(SinVal * 127) + 128);
}
}
private
void
GenerateSquare()
{
int
NumSamples = 200;
double
Frequency = 2;
double
SampleRate = 50;
int
SamplesPerWave = (
int
)(SampleRate / (Frequency * 2));
int
Value = 127;
int
Counter = 0;
for
(
int
i = 0; i < NumSamples; i++)
{
if
(Counter >= SamplesPerWave)
{
Counter = 0;
Value *= -1;
}
SquareBuffer[i] = Value + 127;
Counter++;
}
}
private
void
GenerateSawtooth()
{
int
NumSamples = 200;
double
Frequency = 2;
double
SampleRate = 50;
int
SamplesPerWave = (
int
)(SampleRate / Frequency);
int
Value = 0;
int
Counter = 0;
double
Delta = 255.0 / (
double
)SamplesPerWave;
for
(
int
i = 0; i < NumSamples; i++)
{
if
(Counter >= SamplesPerWave)
{
Counter = 0;
Value = 0;
}
else
{
Value += (
int
)Math.Round(Delta, 0);
if
(Value > 255)
{
Value = 255;
}
}
SawBuffer[i] = Value;
Counter++;
}
}
private
void
AddPoint(
object
sender, EventArgs args)
{
AccelChartPoints.Add(
new
AccelerationChartValue() { Date = DateTime.Now, X = SineBuffer[AccelChartPoints.Count % 200], Y = SquareBuffer[AccelChartPoints.Count % 200], Z = SawBuffer[AccelChartPoints.Count % 200] });
}
}
}
AccelerationChartValue.cs:
using
System;
namespace
ZoomScrollTestApp
{
public
class
AccelerationChartValue
{
public
double
X {
get
;
set
; }
public
double
Y {
get
;
set
; }
public
double
Z {
get
;
set
; }
public
DateTime Date {
get
;
set
; }
}
}
Thanks in advance for you help,
Shawn