Search code examples
livecharts

How do I enter a 'null' value in a LineSeries?


I have a 'line' of values where some information might be missing.

e.g.:

Jan - 10, Feb - 20, Mar - 15, Apr - null, Jun - 45 ... etc

I would expect that in the chart the NULL value will simply appear 'empty' (missing) from the line.

e.g.

enter image description here

I have tried using ChartValues<decimal?> but the chart complains in the XAML that it does not know how to plot Nullable1`.

Help?


Solution

  • LiveCharts uses double.NaN instead of null this is the example in the web site:

    https://lvcharts.net/App/examples/v1/wpf/Missing%20Points

    Series = new SeriesCollection
            {
                new LineSeries
                {
                    Values = new ChartValues<double>
                    {
                        4,
                        5,
                        7,
                        8,
                        double.NaN,
                        5,
                        2,
                        8,
                        double.NaN,
                        6,
                        2
                    }
                }
            };
    

    XAML

    <lvc:CartesianChart Series="{Binding Series}"></lvc:CartesianChart>