Example #1
0
        static Charting()
        {
            Configurations = new Dictionary <Type, ConfigWrapper>();

            // Live.Charts can plot any type, yes even any class defined by yourself.
            // you just need to tell the charts how to plot it.
            // for example the XY Mapper exposes an X and Y method,
            // for example .X( "mapper" ) asks for the function to get the value of a point in X, same with Y
            // live charts will inject a value and an index
            // the value will be of type <T> and the index is only the value of the point in the array.

            //the SeriesMappers class is just a reminder of the configurations that we have, it actually just
            //returns a new instance of the related configuration
            //a configuration is only a holder for the mappers.

            //lets configure <int>

            For <int>(Mappers.Xy <int>()
                      .X((value, index) => index)                               //use the index of the item in the array as X
                      .Y(value => value), SeriesOrientation.Horizontal);        //use the value (of type int integer this case) as Y
            For <int>(Mappers.Xy <int>()
                      .X(value => value)                                        //use the value (int) as X
                      .Y((value, index) => index), SeriesOrientation.Vertical); //use the index of the item in the array as Y

            //OK now lets configure a class I defined, the ObservablePoint class, it only has 2 properties, X and Y

            For <ObservablePoint>(Mappers.Xy <ObservablePoint>() //in this case value is of type <ObservablePoint>
                                  .X(value => value.X)           //use the X property as X
                                  .Y(value => value.Y));         //use the Y property as Y

            //easy, now live charts know how to plot an ObservablePoint class and integers.

            //OK, now lets use another mapper, in this case we are going to configure a class for a PolarChart
            //polar chart requires a Radius and an Angle instead of X and Y
            //so we will just pull the Mappers.Polar configuration
            //and specify which property to use as Radius and which one as Angle
            //in this case the PolarPoint class that I defined only contains these 2 properties.
            //so it is really easy, now value is of type Polar point, because we said so when: SeriesMappers.Polar<PolarPoint>()

            For <PolarPoint>(Mappers.Polar <PolarPoint>()
                             .Radius(value => value.Radius) //use the radius property as radius for the plotting
                             .Angle(value => value.Angle)); //use the angle property as angle for the plotting

            //now a more complex situation
            //the OhclPoint is ready to plot financial points,
            //the financial series requires a Open, High, Low, and Close values at least
            //that is just by definition of a CandleStick series
            //so I created a OhclPoint class, and used the Financial mapper:
            //and again the OhclPoint class only contains those 4 properties
            //we just mapped them correctly and LiveCharts will know how to handle this class.

            //the DateTime for now its tricky....
            //I will explain better later if i do not find a better solution...

            For <OhlcPoint>(Mappers.Financial <OhlcPoint>()
                            .X((value, index) => index)
                            .Open(value => value.Open)
                            .High(value => value.High)
                            .Low(value => value.Low)
                            .Close(value => value.Close), SeriesOrientation.Horizontal);

            For <double>(Mappers.Xy <double>()
                         .X((value, index) => index)
                         .Y(value => value), SeriesOrientation.Horizontal);
            For <double>(Mappers.Xy <double>()
                         .X(value => value)
                         .Y((value, index) => index), SeriesOrientation.Vertical);

            For <decimal>(Mappers.Xy <decimal>()
                          .X((value, index) => index)
                          .Y(value => (double)value), SeriesOrientation.Horizontal);
            For <decimal>(Mappers.Xy <decimal>()
                          .X(value => (double)value)
                          .Y((value, index) => index), SeriesOrientation.Vertical);

            For <short>(Mappers.Xy <short>()
                        .X((value, index) => index)
                        .Y(value => value), SeriesOrientation.Horizontal);
            For <short>(Mappers.Xy <short>()
                        .X(value => value)
                        .Y((value, index) => index), SeriesOrientation.Vertical);

            For <float>(Mappers.Xy <float>()
                        .X((value, index) => index)
                        .Y(value => value), SeriesOrientation.Horizontal);
            For <float>(Mappers.Xy <float>()
                        .X(value => value)
                        .Y((value, index) => index), SeriesOrientation.Vertical);

            For <long>(Mappers.Xy <long>()
                       .X((value, index) => index)
                       .Y(value => value), SeriesOrientation.Horizontal);
            For <long>(Mappers.Xy <long>()
                       .X(value => value)
                       .Y((value, index) => index), SeriesOrientation.Vertical);

            For <ScatterPoint>(Mappers.Weighted <ScatterPoint>()
                               .X(value => value.X)
                               .Y(value => value.Y)
                               .Weight(value => value.Weight));

            For <HeatPoint>(Mappers.Weighted <HeatPoint>()
                            .X(value => value.X)
                            .Y(value => value.Y)
                            .Weight(value => value.Weight));

            For <ObservableValue>(Mappers.Xy <ObservableValue>()
                                  .X((value, index) => index)
                                  .Y(value => value.Value),
                                  SeriesOrientation.Horizontal);
            For <ObservableValue>(Mappers.Xy <ObservableValue>()
                                  .X(value => value.Value)
                                  .Y((value, index) => index),
                                  SeriesOrientation.Vertical);

            For <DateTimePoint>(Mappers.Xy <DateTimePoint>()
                                .X(value => value.DateTime.Ticks)
                                .Y(value => value.Value), SeriesOrientation.Horizontal);
            For <DateTimePoint>(Mappers.Xy <DateTimePoint>()
                                .X(value => value.Value)
                                .Y(value => value.DateTime.Ticks), SeriesOrientation.Vertical);

            For <GanttPoint>(Mappers.Gantt <GanttPoint>()
                             .X((v, i) => - i)
                             .YStart(v => v.StartPoint)
                             .Y(v => v.EndPoint), SeriesOrientation.Horizontal);
            For <GanttPoint>(Mappers.Gantt <GanttPoint>()
                             .Y((v, i) => - i)
                             .XStart(v => v.StartPoint)
                             .X(v => v.EndPoint), SeriesOrientation.Vertical);
        }