/// <summary>
        /// Adds SkiaSharp as the backend provider for LiveCharts.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public static LiveChartsSettings AddSkiaSharp(this LiveChartsSettings settings)
        {
            // ToDo: default paint needs to be simplified???
            LiveCharts.DefaultPaint = DefaultPaintTask;

            return(settings.HasProvider(new SkiaSharpProvider()));
        }
Exemple #2
0
        public static LiveChartsSettings AddSkiaSharp(this LiveChartsSettings settings, Action <StyleBuilder <SkiaSharpDrawingContext> > builder = null)
        {
            return(settings.AddDefaultStyles((StyleBuilder <SkiaSharpDrawingContext> styleBuilder) =>
            {
                // default settings
                styleBuilder
                .UseColors(ColorPacks.MaterialDesign500)
                .UseSeriesInitializer(new DefaultSeriesInitializer());

                // user defined settings
                builder?.Invoke(styleBuilder);
            }));
        }
        //private ZoomingOptions _zoomingMode;
        //private double _maximumXAxis;
        //private double _minimumXAxis;
        //private double _forYAxis;
        public MainWindow()
        {
            InitializeComponent();
            liveChartsSettings  = new LiveChartsSettings();
            multiplicativeModel = new service.MultiplicativeModelServices();
            //DataContext = liveChartsSettings; ==!==

            DataContext = new MultiplicativeViewModel();
            //YFormatter = value => value.ToString("R");

            //modifying the series collection will animate and update the chart

            //modifying any series values will also animate and update the chart
            //SeriesCollection[3].Values.Add(5d);

            //DataContext = this;
        }
Exemple #4
0
        /// <summary>
        /// Adds SkiaSharp as the UI provider for LiveCharts.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public static LiveChartsSettings AddSkiaSharp(this LiveChartsSettings settings)
        {
            return(settings
                   .HasDataFactory(new DataFactory <SkiaSharpDrawingContext>())
                   .HasAxisProvider(() => new Axis())
                   .HasPolarAxisProvider(() => new PolarAxis())
                   .HasDesigerSeriesProvider(kind =>
            {
                var r = new Random();

                var v1 = new int[] { r.Next(0, 10), r.Next(0, 10), r.Next(0, 10), r.Next(0, 10) };
                var v2 = new int[] { r.Next(0, 10), r.Next(0, 10), r.Next(0, 10), r.Next(0, 10) };

                if (kind == DesignerKind.Pie)
                {
                    return new ISeries[] { new PieSeries <int> {
                                               Values = v1
                                           }, new PieSeries <int> {
                                               Values = v2
                                           } }
                }
                ;

                var seed = r.NextDouble();

                return seed > 0.33
                        ? (new ISeries[] { new LineSeries <int> {
                                               Values = v1
                                           }, new LineSeries <int> {
                                               Values = v2
                                           } })
                        : (seed > 0.66
                            ? new ISeries[] { new ColumnSeries <int> {
                                                  Values = v1
                                              }, new ColumnSeries <int> {
                                                  Values = v2
                                              } }
                            : new ISeries[] { new ScatterSeries <int> {
                                                  Values = v1
                                              }, new ScatterSeries <int> {
                                                  Values = v2
                                              } });
            }));
        }
        /// <summary>
        /// Adds the light theme.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="additionalStyles">the additional styles.</param>
        /// <returns></returns>
        public static LiveChartsSettings AddLightTheme(
            this LiveChartsSettings settings, Action <Theme <SkiaSharpDrawingContext> >?additionalStyles = null)
        {
            return(settings
                   .HasTheme((Theme <SkiaSharpDrawingContext> theme) =>
            {
                _ = theme
                    .WithColors(ColorPalletes.MaterialDesign500)
                    .WithStyle(style =>
                               style
                               .HasRuleForCharts(chart =>
                {
                    //chart.BackColor = Color.FromArgb(255, 255, 255, 255);
                    chart.AnimationsSpeed = TimeSpan.FromMilliseconds(700);
                    chart.EasingFunction = EasingFunctions.ExponentialOut;

                    // The point states dictionary defines the fill and stroke to use for a point marked with the
                    // state key, LiveCharts uses this dictionary to highlight a chart point when the mouse is
                    // over a point, for example, the first .WithState() defines that every time a point is marked
                    // with the LiveCharts.BarSeriesHoverKey key, the library will draw a null stroke and
                    // new SKColor(255, 255, 255, 180) as the fill (defaultHoverColor).
                    var defaultHoverColor = Color.FromArgb(180, 255, 255, 255).AsSKColor();
                    chart.PointStates = new PointStatesDictionary <SkiaSharpDrawingContext>()
                                        .WithState(LiveCharts.BarSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor), true)
                                        .WithState(LiveCharts.LineSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor), true)
                                        .WithState(LiveCharts.StepLineSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor), true)
                                        .WithState(LiveCharts.PieSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor), true)
                                        .WithState(LiveCharts.ScatterSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor), true)
                                        .WithState(LiveCharts.StackedBarSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor), true)
                                        .WithState(LiveCharts.HeatSeriesHoverState, null, new SolidColorPaintTask(defaultHoverColor), true);
                })
                               .HasRuleForAxes(axis =>
                {
                    axis.TextSize = 16;
                    axis.ShowSeparatorLines = true;
                    axis.LabelsPaint = DefaultPaintTask;
                    axis.SeparatorsPaint = DefaultPaintTask;
                })
                               // ForAnySeries() will be called for all the series
                               .HasRuleForAnySeries(series =>
                {
                    if (series is not IStrokedAndFilled <SkiaSharpDrawingContext> strokedAndFilled)
                    {
                        return;
                    }
                    strokedAndFilled.Fill = DefaultPaintTask;
                    strokedAndFilled.Stroke = DefaultPaintTask;
                })
                               .HasRuleForLineSeries(lineSeries =>
                {
                    // at this point ForAnySeries() was already called
                    // we are configuring the missing properties
                    lineSeries.GeometrySize = 18;
                    lineSeries.GeometryFill = new SolidColorPaintTask(Color.FromArgb(255, 250, 250, 250).AsSKColor());
                    lineSeries.GeometryStroke = DefaultPaintTask;
                })
                               .HasRuleForStepLineSeries(steplineSeries =>
                {
                    // at this point ForAnySeries() was already called
                    // we are configuring the missing properties
                    steplineSeries.GeometrySize = 18;
                    steplineSeries.GeometryFill = new SolidColorPaintTask(Color.FromArgb(255, 250, 250, 250).AsSKColor());
                    steplineSeries.GeometryStroke = DefaultPaintTask;
                })
                               .HasRuleForStackedLineSeries(stackedLine =>
                {
                    // at this point both ForAnySeries() and ForLineSeries() were already called
                    // again we are correcting the previous settings
                    stackedLine.GeometrySize = 0;
                    stackedLine.GeometryFill = null;
                    stackedLine.GeometryStroke = null;
                    stackedLine.Stroke = null;
                    stackedLine.Fill = DefaultPaintTask;
                })
                               .HasRuleForBarSeries(barSeries =>
                {
                    // only ForAnySeries() has run, a bar series is not
                    // any of the previous types.
                    barSeries.Stroke = null;
                    barSeries.Rx = 4;
                    barSeries.Ry = 4;
                })
                               .HasRuleForStackedBarSeries(stackedBarSeries =>
                {
                    stackedBarSeries.Rx = 0;
                    stackedBarSeries.Ry = 0;
                })
                               .HasRuleForPieSeries(pieSeries =>
                {
                    pieSeries.Fill = DefaultPaintTask;
                    pieSeries.Stroke = null;
                    pieSeries.Pushout = 0;
                })
                               .HasRuleForStackedStepLineSeries(stackedStep =>
                {
                    stackedStep.GeometrySize = 0;
                    stackedStep.GeometryFill = null;
                    stackedStep.GeometryStroke = null;
                    stackedStep.Stroke = null;
                    stackedStep.Fill = DefaultPaintTask;
                })
                               .HasRuleForHeatSeries(heatSeries =>
                {
                    // ... rules here
                })
                               .HasRuleForFinancialSeries(financialSeries =>
                {
                    financialSeries.UpFill = DefaultPaintTask;
                    financialSeries.DownFill = DefaultPaintTask;
                    financialSeries.UpStroke = DefaultPaintTask;
                    financialSeries.DownStroke = DefaultPaintTask;
                }))
                    // finally add a resolver for the DefaultPaintTask
                    // the library already provides the AddDefaultLightResolvers() and AddDefaultDarkResolvers methods
                    // these method only translates 'DefaultPaintTask' to a valid stroke/fill based on
                    // the series context
                    .AddDefaultLightResolvers();

                additionalStyles?.Invoke(theme);
            }));
        }
 /// <summary>
 /// Adds SkiaSharp as the UI provider for LiveCharts.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <returns></returns>
 public static LiveChartsSettings AddSkiaSharp(this LiveChartsSettings settings)
 {
     return(settings
            .HasDataFactory(new DataFactory <SkiaSharpDrawingContext>())
            .HasAxisProvider(() => new Axis()));
 }
Exemple #7
0
        /// <summary>
        /// Adds the light theme.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public static LiveChartsSettings AddDarkTheme(this LiveChartsSettings settings)
        {
            return(settings
                   .HasTheme((Theme <SkiaSharpDrawingContext> theme) =>
            {
                _ = theme
                    .WithColors(ColorPacks.MaterialDesign200)
                    .WithVisualsInitializer(initializer =>
                                            initializer
                                            .ForCharts(chart =>
                {
                    chart.BackColor = Color.FromArgb(255, 40, 40, 40);
                    chart.AnimationsSpeed = TimeSpan.FromMilliseconds(700);
                    chart.EasingFunction = EasingFunctions.ExponentialOut;

                    // The point states dictionary defines the fill and stroke to use for a point marked with the
                    // state key, LiveCharts uses this dictionary to highlight a chart point when the mouse is
                    // over a point, for example, the first .WithState() defines that every time a point is marked
                    // with the LiveCharts.BarSeriesHoverKey key, the library will draw a null stroke and
                    // new SKColor(255, 255, 255, 180) as the fill (defaultHoverColor).
                    var defaultHoverColor = Color.FromArgb(40, 255, 255, 255).AsSKColor();
                    chart.PointStates =
                        new PointStatesDictionary <SkiaSharpDrawingContext>()
                        .WithState(
                            LiveCharts.BarSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor))
                        .WithState(
                            LiveCharts.LineSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor))
                        .WithState(
                            LiveCharts.PieSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor))
                        .WithState(
                            LiveCharts.ScatterSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor))
                        .WithState(
                            LiveCharts.StackedBarSeriesHoverKey, null, new SolidColorPaintTask(defaultHoverColor));
                })
                                            .ForAxes(axis =>
                {
                    axis.TextSize = 18;
                    axis.ShowSeparatorLines = true;
                    axis.TextBrush = DefaultPaintTask;
                    axis.SeparatorsBrush = DefaultPaintTask;
                })
                                            // ForAnySeries() will be called for all the series
                                            .ForAnySeries(series =>
                {
                    series.Fill = DefaultPaintTask;
                    series.Stroke = DefaultPaintTask;
                })
                                            .ForLineSeries(lineSeries =>
                {
                    // at this point ForAnySeries() was already called
                    // we are configuring the missing properties
                    lineSeries.GeometrySize = 18;
                    lineSeries.GeometryFill = new SolidColorPaintTask(Color.FromArgb(255, 40, 40, 40).AsSKColor());
                    lineSeries.GeometryStroke = DefaultPaintTask;
                })
                                            .ForStackedLineSeries(stackedLine =>
                {
                    // at this point both ForAnySeries() and ForLineSeries() were already called
                    // again we are correcting the previous settings
                    stackedLine.GeometrySize = 0;
                    stackedLine.GeometryFill = null;
                    stackedLine.GeometryStroke = null;
                    stackedLine.Stroke = null;
                    stackedLine.Fill = DefaultPaintTask;
                })
                                            .ForBarSeries(barSeries =>
                {
                    barSeries.Rx = 6;
                    barSeries.Ry = 6;
                })
                                            .ForStackedBarSeries(stackedBarSeries =>
                {
                    stackedBarSeries.Rx = 0;
                    stackedBarSeries.Ry = 0;
                })
                                            .ForPieSeries(pieSeries =>
                {
                    pieSeries.Fill = DefaultPaintTask;
                    pieSeries.Stroke = null;
                    pieSeries.Pushout = 0;
                }))
                    // finally add a resolver for the DefaultPaintTask
                    // the library already provides the AddDefaultResolvers() method
                    // this method only translates 'DefaultPaintTask' to a valid stroke/fill based on
                    // the series context
                    .AddDefaultDarkResolvers();
            }));
        }
Exemple #8
0
    /// <summary>
    /// Adds the light theme.
    /// </summary>
    /// <param name="settings">The settings.</param>
    /// <param name="additionalStyles">the additional styles.</param>
    /// <returns></returns>
    public static LiveChartsSettings AddLightTheme(
        this LiveChartsSettings settings, Action <Theme <SkiaSharpDrawingContext> >?additionalStyles = null)
    {
        return(settings
               .HasTheme((Theme <SkiaSharpDrawingContext> theme) =>
        {
            _ = theme
                .WithColors(ColorPalletes.MaterialDesign500)
                .WithStyle(style =>
                           style
                           .HasRuleForCharts(chart =>
            {
                chart.AnimationsSpeed = TimeSpan.FromMilliseconds(800);
                chart.EasingFunction = EasingFunctions.ExponentialOut;
            })
                           .HasRuleForAxes(axis =>
            {
                axis.TextSize = 16;
                axis.ShowSeparatorLines = true;
                axis.NamePaint = LiveChartsSkiaSharp.DefaultPaint;
                axis.LabelsPaint = LiveChartsSkiaSharp.DefaultPaint;
                axis.SeparatorsPaint = LiveChartsSkiaSharp.DefaultPaint;
            })
                           // ForAnySeries() will be called for all the series
                           .HasRuleForAnySeries(series =>
            {
                if (series is not IStrokedAndFilled <SkiaSharpDrawingContext> strokedAndFilled)
                {
                    return;
                }
                strokedAndFilled.Fill = LiveChartsSkiaSharp.DefaultPaint;
                strokedAndFilled.Stroke = LiveChartsSkiaSharp.DefaultPaint;
            })
                           .HasRuleForLineSeries(lineSeries =>
            {
                // at this point ForAnySeries() was already called
                // we are configuring the missing properties
                lineSeries.GeometrySize = 18;
                lineSeries.GeometryFill = new SolidColorPaint(LvcColor.FromArgb(255, 250, 250, 250).AsSKColor());
                lineSeries.GeometryStroke = LiveChartsSkiaSharp.DefaultPaint;
            })
                           .HasRuleForStepLineSeries(steplineSeries =>
            {
                // at this point ForAnySeries() was already called
                // we are configuring the missing properties
                steplineSeries.GeometrySize = 18;
                steplineSeries.GeometryFill = new SolidColorPaint(LvcColor.FromArgb(255, 250, 250, 250).AsSKColor());
                steplineSeries.GeometryStroke = LiveChartsSkiaSharp.DefaultPaint;
            })
                           .HasRuleForStackedLineSeries(stackedLine =>
            {
                // at this point both ForAnySeries() and ForLineSeries() were already called
                // again we are correcting the previous settings
                stackedLine.GeometrySize = 0;
                stackedLine.GeometryFill = null;
                stackedLine.GeometryStroke = null;
                stackedLine.Stroke = null;
                stackedLine.Fill = LiveChartsSkiaSharp.DefaultPaint;
            })
                           .HasRuleForBarSeries(barSeries =>
            {
                // only ForAnySeries() has run, a bar series is not
                // any of the previous types.
                barSeries.Stroke = null;
                barSeries.Rx = 4;
                barSeries.Ry = 4;
            })
                           .HasRuleForStackedBarSeries(stackedBarSeries =>
            {
                stackedBarSeries.Rx = 0;
                stackedBarSeries.Ry = 0;
            })
                           .HasRuleForPieSeries(pieSeries =>
            {
                pieSeries.Fill = LiveChartsSkiaSharp.DefaultPaint;
                pieSeries.Stroke = null;
                pieSeries.Pushout = 0;
            })
                           .HasRuleForStackedStepLineSeries(stackedStep =>
            {
                stackedStep.GeometrySize = 0;
                stackedStep.GeometryFill = null;
                stackedStep.GeometryStroke = null;
                stackedStep.Stroke = null;
                stackedStep.Fill = LiveChartsSkiaSharp.DefaultPaint;
            })
                           .HasRuleForHeatSeries(heatSeries =>
            {
                // ... rules here
            })
                           .HasRuleForFinancialSeries(financialSeries =>
            {
                financialSeries.UpFill = LiveChartsSkiaSharp.DefaultPaint;
                financialSeries.DownFill = LiveChartsSkiaSharp.DefaultPaint;
                financialSeries.UpStroke = LiveChartsSkiaSharp.DefaultPaint;
                financialSeries.DownStroke = LiveChartsSkiaSharp.DefaultPaint;
            })
                           .HasRuleForPolarLineSeries(polarLine =>
            {
                polarLine.GeometrySize = 18;
                polarLine.GeometryFill = new SolidColorPaint(LvcColor.FromArgb(255, 250, 250, 250).AsSKColor());
                polarLine.GeometryStroke = LiveChartsSkiaSharp.DefaultPaint;
            }))
                // finally add a resolver for the DefaultPaintTask
                // the library already provides the AddDefaultLightResolvers() and AddDefaultDarkResolvers methods
                // this method only translates 'DefaultPaintTask' to a valid stroke/fill based on
                // the series context
                .AddDefaultLightResolvers();

            additionalStyles?.Invoke(theme);
        }));
    }
Exemple #9
0
 /// <summary>
 /// Adds SkiaSharp as the backend provider for LiveCharts.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <returns></returns>
 public static LiveChartsSettings AddSkiaSharp(this LiveChartsSettings settings)
 {
     return(settings.HasProvider(new SkiaSharpProvider()));
 }