This project is read-only.

Can I change the HorizontalAxis string?

Sep 2, 2012 at 3:00 PM
Edited Sep 2, 2012 at 3:00 PM

I want to make a project with a line in realtime..

So I want to the HorizontalAxis show this string of time like that "11:20 11:21 ....11:30",but i don't how to do it?


I find this code :

private ObservableDataSource<Point> dataSource = new ObservableDataSource<Point>();

the Point is with (double, double), it can't help me...


How could i do ? thank you,

Oct 2, 2012 at 10:20 AM

Its all in the mapping

I have a class called DatePoint:

public class DatePoint
    public DatePoint()
        X = new DateTime(1900, 1, 1);
        Y = Double.NaN;

    public DatePoint Clone()
        return new DatePoint(X, Y);

    public DatePoint(DateTime x, double y) { X = x; Y = y; }
    public DateTime X { set; get; }
    public double Y { set; get; }

with that I use ObservableDataSource<DatePoint> for my collection and for the plotter I use GenericChartPlotter<DateTime, double> in order to keep my window xaml nice and neat I extended it like so:

public class DateTimeChartPlotter : GenericChartPlotter<DateTime, double> { }

Now for the tricky part, like I said in the beginning its all in the mapping you need to set the mapping from your point (DateTime, double) to a "screen" point (double, double) and this is how:

HorizontalDateTimeAxis axis = plotter.HorizontalAxis as HorizontalDateTimeAxis;
points.SetYMapping(p => p.Y);
points.SetXMapping(p => axis.ConvertToDouble(p.X));

As you can see since Y is a double its mapped as is but X is DateTime so you take the mapping function from the DateTimeAxis of the plotter and use it to convert DateTime into double in a way it will fit with the plotter.

The mapping is set on the collection so you need to do this for each collection you want to add to the plotter (i.e. use plotter.AddLineGraph), also since you set a plotter's mapping on to a collection you can't show the same exact collection on two different plotters (although you can create a copy collection and use that).

good luck

Jul 28, 2013 at 7:58 PM
Thanks roey_nissim! This was driving me nuts..
Delegating the DateTime=>Double conversion to the Axis was what I was missing.
Sep 3, 2013 at 5:50 AM
Just if any1 wonders - HorizontalDateTimeAxis is in Microsoft.Research.DynamicDataDisplay.Charts namespace.