Hello Infragistics Engineers,
I've attached a sample that demonstrates some buggy behavior when trying to add a Series to a chart using procedural code.
Using the same function to add a series in the OnInitialized function produces different results than the same function used after the window is fully visible (which actually doesn't even work).
Maybe this is already fixed in a yet-to-be-released build? Or there's a funny, specific way adding a Series should be done?
It would be nice to have in the docs a little more hand-holding/in-depth explanation on using the chart from procedural code.
XamChart is shaping up pretty nicely in most other areas. Keep up the good work.
Thanks,
Zac Morris
Sample:
XAML:
<igCA:XamChart x:Name="_chart" />
CS:
using System;using System.Collections.Generic;using System.Windows;using System.Windows.Input;using System.Windows.Media;using Infragistics.Windows.Chart;namespace ChartSeriesBug{ public partial class Window1 : Window { public Window1() { InitializeComponent(); _chart.MouseDoubleClick += _chart_MouseDoubleClick; } private void _chart_MouseDoubleClick(object sender, MouseButtonEventArgs e) { this.AddSeries(new Random().Next(), "After Initialized Procedural Series"); } protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); for (int i = 0; i < 2; i++) { this.AddSeries(i, "OnInitialized Procedural Series"); } } private void AddSeries(int i, string seriesLabel) { Series series = new Series(); series.ChartType = ChartType.Line; series.Label = seriesLabel; series.DataMapping = "Value=Watts; Label=Time"; series.DataPointColor = DataPointColor.Auto; series.StrokeThickness = 2; series.Fill = Brushes.Red; series.Stroke = Brushes.Aqua; series.DataSource = new RandomReadings(i); _chart.Series.Add(series); } } public class RandomReadings : List<PowerReading> { public RandomReadings(int offset) { for (int i = 0; i < 10; i++) { this.Add(new PowerReading { Time = new DateTime(2007, 12, 1, i, 0, 0), Watts = i + offset } ) ; } } } public class PowerReading { public DateTime Time { get; set; } public double Watts { get; set; } }}
Thanks Goran, that's done the trick.
I notice that the chart seems to ignore the Stroke property of the series, but I'm sure that's probably already fixed for the final version.
Hello Zac,
Before you set the data source you have to add series to the chart. Your AddSeries method should be changed on the following way:
private void AddSeries(int i, string seriesLabel) { Series series = new Series();
_chart.Series.Add(series);
series.ChartType = ChartType.Line;
series.Label = seriesLabel;
series.DataMapping = "Value=Watts; Label=Time";
series.DataPointColor = DataPointColor.Auto;
series.StrokeThickness = 2;
series.Fill = Brushes.Red;
series.Stroke = Brushes.Aqua;
series.DataSource = new RandomReadings(i); }
This behaviour of the chart beta was changed and your first sample will work with the final version of the chart.
GoranS