Bram
Bram

Reputation: 473

Setting a min value of an axis in Live Charts graph

I'm using Live Charts library and I've run into a problem where the y axis has "-1000" as the min value.

enter image description here

How do I set this to 0? I tried in the winforms under the Yaxis collection and setting MinValue to 0 there but that doesn't seem to do anything.

This is how I draw the chart:

cartesianChart1.Series.Add(
    new LineSeries
    {
        Title = "Series 1",
        Values = graph1.ReturnGraphData().AsChartValues(),
        LineSmoothness = 0, //straight lines, 1 really smooth lines
        PointGeometry = null,
        PointGeometrySize = 0,
    });

the method "ReturnGraphData()" returns an int-array.

Also this are my settings of the YAxis in winforms designer:

enter image description here

Like i said earlier when I set MinValues to 0 in the properties it either doens't do anything or crashes Visual Studio. It also reverts to NaN.

Upvotes: 3

Views: 11213

Answers (1)

Bram
Bram

Reputation: 473

I found a way that works:

        cartesianChart1.AxisY.Clear();

        cartesianChart1.AxisY.Add(
        new Axis
        {
            MinValue = 0 
        });

        cartesianChart1.Series.Add(
        new LineSeries
        {
            Title = "Series 1",
            Values = model.ImageGraphData().AsChartValues(),
            LineSmoothness = 0, //straight lines, 1 really smooth lines
            PointGeometry = null,
            PointGeometrySize = 0,
        });

In this code sample I'm clearing all the existing YAxis and then adding one with MinValue = 0. What I was doing wrong before was trying to add a new YAxis after the graph was drawn, which didn't seem to work. However the fact that setting MinValue = 0 in the WinForms designer doesn't work is still weird to me.

Upvotes: 8

Related Questions