예제 #1
0
        public Chart()
        {
            InitializeComponent();
            cartesianChart1.Series = new SeriesCollection();

            var mapper = Mappers.Financial <OHLCPointModel>()
                         .X((value, index) => TimeSpan.FromTicks(value.DateTime.Ticks).TotalMinutes)
                         .Open(value => value.Open)
                         .High(value => value.High)
                         .Low(value => value.Low)
                         .Close(value => value.Close);

            var mapperXY = Mappers.Xy <ValuePointModel>()
                           .X((value) => TimeSpan.FromTicks(value.DateTime.Ticks).TotalMinutes)
                           .Y(value => value.Value);

            LiveCharts.Charting.For <ValuePointModel>(mapperXY, SeriesOrientation.Horizontal);
            LiveCharts.Charting.For <OHLCPointModel>(mapper, SeriesOrientation.Horizontal);

            cartesianChart1.AxisX.Add(new Axis
            {
                DisableAnimations = false,
                LabelFormatter    = value => convertTimeToY(value),
                Title             = "Vreme",
                MinRange          = 5
            });
            cartesianChart1.AxisY.Add(new Axis
            {
                LabelFormatter = val => Math.Round(val, 2).ToString() + "$"
            });
            //The next code simulates data changes every 500
            cartesianChart1.Zoom = ZoomingOptions.X;
        }
예제 #2
0
        public ChartHelper()
        {
            var tradeBaseMapper = Mappers.Xy <TradeBase>()
                                  .X(model => model.Time.Ticks)
                                  .Y(model => Convert.ToDouble(model.Price));

            Charting.For <TradeBase>(tradeBaseMapper);

            var tradeMapper = Mappers.Xy <Trade>()
                              .X(model => model.Time.Ticks)
                              .Y(model => Convert.ToDouble(model.Price));

            Charting.For <Trade>(tradeMapper);

            var timeValuePointMapper = Mappers.Xy <TimeValuePoint>()
                                       .X(model => model.X.Ticks)
                                       .Y(model => Convert.ToDouble(model.Y));

            Charting.For <TimeValuePoint>(timeValuePointMapper);

            var candlestickMapper = Mappers.Financial <Candlestick>()
                                    .X((model, index) => index)
                                    .Open(model => Convert.ToDouble(model.Open))
                                    .High(model => Convert.ToDouble(model.High))
                                    .Low(model => Convert.ToDouble(model.Low))
                                    .Close(model => Convert.ToDouble(model.Close));

            Charting.For <Candlestick>(candlestickMapper, SeriesOrientation.Horizontal);
        }
        static DataProviderPoint()
        {
            //lets configure our charts to plot DataProviderPoint
            //a global mapper should only be set once.
            //thus we are using the static constructor of DataProviderPoint

            //lets define a mapper
            var mapper = Mappers.Financial<DataProviderPoint>()
                .Open(x => x.Open)
                .High(x => x.High)
                .Low(x => x.Low)
                .Close(x => x.Close);

            //lets save the mapper globally, for more info please see:
            //https://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration
            Charting.For<DataProviderPoint>(mapper);
        }
        public CandleChartUserControl()
        {
            GlobalVariables.CandleChartUserControl = this;

            InitializeComponent();


            // In DesignMode, it avoid read app.config fail exception(in this case, cannot read "connectionString" from app.config)
            // DesignMode use compiled UserControl which doesn't include app.config file, so every behavior that read/connect
            // app.config file data throws exception
            // This prevents program from continues when it is design mode
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }


            var mapper = Mappers.Financial <QuoteDaily>()
                         .Open(model => model.Open)
                         .Close(model => model.Close)
                         .High(model => model.High)
                         .Low(model => model.Low)
                         .X(model => model.Date.Ticks);

            Charting.For <QuoteDaily>(mapper);

            ChartValues = new ChartValues <QuoteDaily>();

            DateTimeFormatter = value => new DateTime((long)value).ToString("yyyy-MM-dd");

            AxisStep = TimeSpan.FromDays(20).Ticks;

            AxisUnit = TimeSpan.TicksPerDay;

            SetAxisLimits(DateTime.Now, DateTime.Now.AddDays(-100));

            DataContext = this;
        }
예제 #5
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);
        }