Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LiveCharts WPF poor rendering performance

Tags:

wpf

livecharts

I am building a WPF tool for visualizing data for reefer containers (cooling containers). Pretty simple plot of sensor data (temperatures, setpoint, humidity).
Problem is rendering performance. The data is loaded blazingly fast via REST API. After reformatting the values to DateTimePoints (takes 1ms) they get set as geared values on bound SeriesCollection. Immediately after setting the values the application freezes for 10 seconds, renders the chart stutterly and the whole apllication isn't usable anymore. I worked all the examples and demos but I can't get LiveCharts to perform in a usable fashion and I don't know what am I doing wrong here

CartesianChart
3x GStepLineSeries with (in this case) 626 Values per series
XAxisFormatter DateTimePoint

I have no idea what I am doing wrong. Is 1900 GearedValues Values too much? Is LiveCharts that shitty?

CartesianChart GStepLineSeries enter image description here

 public GStepLineSeries SupplyTemperatures
    {
        get { return _supplyTemperatures ?? (_supplyTemperatures = new GStepLineSeries() { Title = "Supply" }); }
        set
        {
            _supplyTemperatures = value;
            RaisePropertyChanged();
        }
    }

    public GStepLineSeries ReturnTemperatures
    {
        get { return _returnTemperatures ?? (_returnTemperatures = new GStepLineSeries { Title = "Return" }); }
        set
        {
            _returnTemperatures = value;
            RaisePropertyChanged();
        }
    }

    public GStepLineSeries Setpoints
    {
        get
        {
            return _setpoints ?? (_setpoints = new GStepLineSeries
            {
                Title = "Setpoint",
                Fill = Brushes.Transparent,
                PointGeometry = null
            });
        }
        set
        {
            _setpoints = value;
            RaisePropertyChanged();
        }
    }

    public SeriesCollection ReeferDataTemperatureSeries
    {
        get
        {
            if (_reeferDataTemperatureSeries == null)
            {
                _reeferDataTemperatureSeries =
                    new SeriesCollection(GetSeriesConfig()) { SupplyTemperatures, ReturnTemperatures, Setpoints };

            }

            return _reeferDataTemperatureSeries;
        }
        set
        {
            _reeferDataTemperatureSeries = value;
            RaisePropertyChanged();
        }
    }

    private CartesianMapper<DateTimePoint> GetSeriesConfig()
    {
        return Mappers.Xy<DateTimePoint>()
            .X(rdcv => (double)rdcv.DateTime.Ticks)
            .Y(rdcv => rdcv.Value);
    }

Xaml:

     <lvc:CartesianChart
                                Height="800"
                                DisableAnimations="True"
                                IsManipulationEnabled="False"
                                LegendLocation="Top"
                                Series="{Binding ReeferDataTemperatureSeries}">

                                <lvc:CartesianChart.AxisX>
                                    <lvc:Axis
                                        Title="Time"
                                        LabelFormatter="{Binding ReeferDataFormatter}"
                                        RangeChanged="Axis_OnRangeChanged"
                                        Separator="{x:Static lvc:DefaultAxes.CleanSeparator}" />
                                </lvc:CartesianChart.AxisX>
                                <lvc:CartesianChart.AxisY>
                                    <lvc:Axis Title="Temperature" />
                                </lvc:CartesianChart.AxisY>
                            </lvc:CartesianChart>
like image 518
Tim van Peterson Avatar asked Nov 19 '22 06:11

Tim van Peterson


1 Answers

I was able to get the graph to draw in about 1.5 seconds with 1,000 data points in each series by making a few changes

  • Set "Hoverable" to false on the chart
  • Make the point geometry null on all series

My version of the code also used the standard chart not the geared version as I don't have a licence for that so it might be even quicker for you.

like image 132
Kevin Ross Avatar answered Mar 16 '23 09:03

Kevin Ross