Search code examples
c#wpflabelaxislivecharts

C# wpf Live charts how to Autoadapt axis in terms of values and labels with code behind


I have a project that has to be developed in WPF and code behind only with Live charts. The idea is to have a temperature graph. Below you can see what I have already been doing by adding values to the lineSerie. I start by adding values to the line serie and when more than 120 I remove the first one:

lineSerie1_Part.Values.Add(new ObservableValue((double)val));
if (lineSerie1_Part.Values.Count >= 120)
        lineSerie1_Part.Values.RemoveAt(0);

enter image description here

Now I have two problems:


  1. I would like not to have on the X axis the number of added values but the time when the temperature has been taken (e.g. 10:03:24 - 10:04:18 - ...). I have therefore written a small test program in which I set the labels:

    Labels = new[] { "AAA", "BBB", "CCC"};
    cc.AxisX[0].Labels = Labels;
    

and that works. That said I can't change it:

Labels[0] = "DDD";
Labels[1] = "EEE";
Labels[2] = "FFF";      
cc.AxisX[0].Labels = Labels;

does not make any change. Additionally, is that the right way to do it? Would there be a way that when I add a new value, that value already has in it its x axis label?


  1. I may set the max and min temperature at the beginning (e.g. 18°-25°),

    chartTemperatures.AxisY.Add(new Axis { MinValue = MinTemp, MaxValue = MaxTemp);
    

but I would like the graphic to automatically extend if the temperature exceeds the initial values (e.g. 25.5°).

Thanks for any help Patrick


Solution

  • As stated by Jdweng there is not automatic method. So I have to use cc.AxisX[0].Label[0] = "DDD";cc.AxisX[0].Label[1] = "EEE";cc.AxisX[0].Label[2] = "FFF"