ObservableDataSource<Point> is displaying wrong cahrt

Apr 23, 2009 at 1:50 PM
Hi,

I made two samples one using ObservableDataSource<Point> and other using CompositeDataSource. But both behaving defferently. CompositeDataSource is giving correct data
I am pasting the both methods here. Please let me know how to do the same using ObservableDataSource<Point> . Because I have to append the data. ObservableDataSource<Point> supports better.

Why both methods behaving differently. Or the code I did is worng.

//This is with ObservableDataSource<Point>

LineGraph chart;

ObservableDataSource<Point> source1 = null;

private void SimulationFromFile1()

{

     //this.plotter.Children.Remove(chart);

     source1 = new ObservableDataSource<Point>();

     source1.SetXYMapping(p => p);

 

     CultureInfo culture = CultureInfo.InvariantCulture;

     string[] strings = File.ReadAllLines("customvalues.txt");

         

     string line0 = strings[0];

     string[] subLines0 = line0.Split(',');

     double x0 = Double.Parse(subLines0[0], culture);

 

     string lineend = strings[strings.Length-1];

     string[] subLinesend = lineend.Split(',');

     double xend = Double.Parse(subLinesend[0], culture);

 

     DateTime starttime = DateTime.FromOADate(x0);

     DateTime endtime = DateTime.FromOADate(xend);

 

     for (int i = 0; i < strings.Length; i++)

     {

          string line = strings[i];

          string[] subLines = line.Split(',');

 

          double x = Double.Parse(subLines[0], culture);

          DateTime dt = DateTime.FromOADate(x);

          double y1 = Double.Parse(subLines[1], culture);

          Point p1 = new Point(dt.ToOADate(), y1);  

          source1.AppendAsync(Dispatcher, p1);

     }

 

     double xMin = dateAxis.ConvertToDouble(starttime);

     double xMax = dateAxis.ConvertToDouble(endtime);

 

     Rect visibleRect = new Rect(xMin, -12, xMax - xMin, 24);

     this.plotter.Viewport.Visible = visibleRect;

     chart = plotter.AddLineGraph(source1, 2, "Data row 1");

}

 

//This is with CompositeDataSource

 

List<double> y;

List<DateTime> date;

EnumerableDataSource<double> ys;

EnumerableDataSource<DateTime> xs;

CompositeDataSource ds;

private void SimulationFromFile2()

{

     CultureInfo culture = CultureInfo.InvariantCulture;

     string[] strings = File.ReadAllLines("customvalues.txt");

 

     DateTime starttime;

     DateTime endtime;

 

     for (int i = 0; i < strings.Length; i++)

     {

          string line = strings[i];

          string[] subLines = line.Split(',');

 

          double x = Double.Parse(subLines[0], culture);

          date.Add(DateTime.FromOADate(x));

          y.Add(Double.Parse(subLines[1], culture));

     }

 

     double xMin = dateAxis.ConvertToDouble(date[0]);

     double xMax = dateAxis.ConvertToDouble(date[date.Count-1]);

 

 

     Rect visibleRect = new Rect(xMin, -12, xMax - xMin, 24);

     this.plotter.Viewport.Visible = visibleRect;

 

     this.ys = new EnumerableDataSource<double>(this.y);

     this.ys.SetYMapping(_x => _x);

     this.xs = new EnumerableDataSource<DateTime>(this.date);

     this.xs.SetXMapping(this.dateAxis.ConvertToDouble);

     CompositeDataSource ds = new CompositeDataSource(xs,ys);

     chart = this.plotter.AddLineGraph(ds, 2, "Data row 1");

 

}


How to attach file to this forum. If required I will attach the text file what I used in this code

Regards
Ravi.