コード例 #1
0
    public ViewModel()
    {
        Series = new ObservableCollection <ISeries>
        {
            new ColumnSeries <double>
            {
                Values = new ObservableCollection <double> {
                    2, 5, 4, -2, 4, -3, 5
                },
                Stroke = null,
                Fill   = new SolidColorPaint {
                    Color = SKColors.DarkOliveGreen
                }
            }
        };

        // Places the axis to the right (or top for X axes)
        _selectedPosition = AxisPosition.End;

        XAxes = new List <Axis>
        {
            new()
            {
                //Name = "X axis",
                TextSize = 20,

                // LabelsPaint = null will not draw the axis labels.
                LabelsPaint = new SolidColorPaint {
                    Color = SKColors.CornflowerBlue
                },

                // SeparatorsPaint = null will not draw the separator lines
                SeparatorsPaint = new SolidColorPaint {
                    Color = SKColors.LightBlue, StrokeThickness = 3
                },

                Position = _selectedPosition
            }
        };

        YAxes = new List <Axis>
        {
            new()
            {
                //Name = "Y axis",
                TextSize    = 20,
                LabelsPaint = new SolidColorPaint {
                    Color = SKColors.Red
                },
                SeparatorsPaint = new SolidColorPaint {
                    Color = SKColors.LightPink, StrokeThickness = 3
                },
                Position = _selectedPosition
            }
        };
    }
コード例 #2
0
    public ViewModel()
    {
        Series = new ObservableCollection <ISeries>
        {
            new LineSeries <double>
            {
                Values = new ObservableCollection <double> {
                    200, 558, 458, 249, 457, 339, 587
                },
            }
        };

        XAxes = new List <Axis>
        {
            new()
            {
                // Use the Label property to indicate the format of the labels in the axis
                // The Labeler takes the value of the label as parameter and must return it as string
                Labeler = (value) => "Day " + value,

                // The MinStep property lets you define the minimum separation (in chart values scale)
                // between every axis separator, in this case we don't want decimals,
                // so lets force it to be greater or equals than 1
                MinStep = 1,

                // labels rotations is in degrees (0 - 360)
                LabelsRotation = 0,

                SeparatorsPaint = new SolidColorPaint(SKColors.LightGray, 2)
            }
        };

        YAxes = new List <Axis>
        {
            new()
            {
                LabelsRotation = _sliderValue,

                // Now the Y axis we will display it as currency
                // LiveCharts provides some common formatters
                // in this case we are using the currency formatter.
                Labeler = Labelers.Currency,

                // you could also build your own currency formatter
                // for example:
                // Labeler = (value) => value.ToString("C")

                // But the one that LiveCharts provides creates shorter labels when
                // the amount is in millions or trillions

                SeparatorsPaint = new SolidColorPaint(SKColors.LightGray, 2)
            }
        };
    }
コード例 #3
0
    /// <inheritdoc cref="IPaint{TDrawingContext}.CloneTask" />
    public override IPaint <SkiaSharpDrawingContext> CloneTask()
    {
        var clone = new SolidColorPaint
        {
            Style           = Style,
            IsStroke        = IsStroke,
            IsFill          = IsFill,
            Color           = Color,
            IsAntialias     = IsAntialias,
            StrokeThickness = StrokeThickness,
            StrokeCap       = StrokeCap,
            StrokeJoin      = StrokeJoin,
            StrokeMiter     = StrokeMiter,
            FontFamily      = FontFamily,
            PathEffect      = PathEffect?.Clone(),
            ImageFilter     = ImageFilter?.Clone()
        };

        return(clone);
    }
コード例 #4
0
    public static void Generate(MotionCanvas <SkiaSharpDrawingContext> canvas)
    {
        var r = new Random();
        var p = new SolidColorPaint(SKColors.Blue, 3)
        {
            IsFill = true
        };

        canvas.AddDrawableTask(p);

        for (var i = 0; i < 1000; i++)
        {
            var circle = new CircleGeometry {
                X = r.Next(15, 285), Y = r.Next(15, 285), Width = 5, Height = 5
            };

            _ = circle
                .TransitionateProperties(
                nameof(circle.X), nameof(circle.Y))
                .WithAnimation(animation =>
                               animation
                               .WithDuration(TimeSpan.FromSeconds(1))
                               .WithEasingFunction(EasingFunctions.ElasticOut))
                .CompleteCurrentTransitions();

            //circle.SetPropertiesTransitions(
            //    new Animation(EasingFunctions.ElasticOut, TimeSpan.FromSeconds(1)),
            //    nameof(circle.X), nameof(circle.Y));
            //circle.CompleteAllTransitions();

            p.AddGeometryToPaintTask(canvas, circle);

            circle.X = r.Next(15, 285);
            circle.Y = r.Next(15, 285);
        }

        canvas.Invalidate();
    }
        internal string ChartDataFor(MeasurementComparisonDictionary sourceData, AxisLimits limits, Size size)
        {
            InitChart(size);
            var axisPaint = new SolidColorPaint(AxisColor)
            {
                StrokeThickness = LineThickness
            };
            var timeUnit = limits.TimeUnit;

            limits.EnsureNonZeroRanges();
            InitSeries(sourceData, limits.StartTimestamp, timeUnit);
            _chart.Sections = new List <RectangularSection>()
                              .Append(new RectangularSection {
                Xi = 0, Xj = 0, Stroke = axisPaint
            })
                              .Append(new RectangularSection {
                Yi = 0, Yj = 0, Stroke = axisPaint
            });
            _chart.XAxes = CreateAxes(limits.X, XAxisTitleTemplate.FillIn(timeUnit.Caption));

            _chart.YAxes = CreateAxes(limits.Y, YAxisTitle);
            return(AsBase64PngString());
        }
        private void InitSeries(
            MeasurementComparisonDictionary sourceData,
            DateTime baseTimestamp,
            TimeUnitForDisplay timeUnit)
        {
            _expectedSeries = new LineSeries <ObservablePoint>
            {
                Values         = new List <ObservablePoint>(),
                Fill           = null,
                LineSmoothness = 0,
                GeometrySize   = 0,
                Stroke         = new SolidColorPaint(ExpectedColor)
                {
                    StrokeThickness = LineThickness, PathEffect = new DashEffect(new[] { 5f, 5f })
                },
                Name = ExpectedCaption
            };
            _actualSeries = new LineSeries <ObservablePoint>
            {
                Values         = new List <ObservablePoint>(),
                Fill           = null,
                LineSmoothness = 0,
                GeometrySize   = 0,
                Stroke         = new SolidColorPaint(ActualColor)
                {
                    StrokeThickness = LineThickness + 1
                },
                Name = ActualCaption
            };
            var errorPaint = new SolidColorPaint(FailColor);

            _failSeries = new LineSeries <ObservablePoint, CircleGeometry>
            {
                GeometrySize   = 9,
                Values         = new List <ObservablePoint>(),
                Fill           = null,
                Stroke         = null,
                GeometryStroke = errorPaint,
                GeometryFill   = errorPaint,
                LineSmoothness = 0,
                Name           = FailCaption
            };

            foreach (var key in sourceData.Keys)
            {
                var xValue    = timeUnit.ConvertFromSeconds((key - baseTimestamp).TotalSeconds);
                var value     = sourceData[key].Value;
                var expectedY = value.ExpectedValueOut?.To <double>();
                // if we have a non-convertible value, return null, so it is skipped
                var actualY = value.ActualValueOut?.ToWithDefault <double?>(null);
                // ensure that IsGood issues are also marked as failures.
                var pass = sourceData[key].IsOk();

                var failValue = actualY ?? expectedY;
                AddPoint(_expectedSeries, xValue, expectedY);
                AddPoint(_actualSeries, xValue, actualY);
                if (pass)
                {
                    continue;
                }
                AddPoint(_failSeries, xValue, failValue);
            }

            var chartSeries = new List <ISeries> {
                _actualSeries, _expectedSeries
            };
            var errors = _failSeries.Values as List <ObservablePoint>;

            Debug.Assert(errors != null, nameof(errors) + " != null");
            if (errors.Any())
            {
                chartSeries.Add(_failSeries);
            }
            _chart.Series          = chartSeries;
            _chart.DrawMarginFrame = new DrawMarginFrame
            {
                Fill   = new SolidColorPaint(ChartColor),
                Stroke = new SolidColorPaint(MajorGridColor)
            };
        }