简体   繁体   English

C#wpf实时图表如何使用代码隐藏的值和标签自动添加轴

[英]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. 我有一个项目必须在WPF中开发,代码仅在Live图表后面。 The idea is to have a temperature graph. 想法是有一个温度图。 Below you can see what I have already been doing by adding values to the lineSerie. 在下面,您可以通过向lineSerie添加值来查看我一直在做的事情。 I start by adding values to the line serie and when more than 120 I remove the first one: 我首先向行系列添加值,当超过120时,我删除第一个:

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

在此输入图像描述

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 (eg 10:03:24 - 10:04:18 - ...). 我不想在X轴上有加值的数量,而是温度的时间(例如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? 有没有办法当我添加一个新值时,该值已经包含在其x轴标签中?


  1. I may set the max and min temperature at the beginning (eg 18°-25°), 我可以在开始时设置最高和最低温度(例如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 (eg 25.5°). 但如果温度超过初始值(例如25.5°),我希望图形自动延伸。

Thanks for any help Patrick 谢谢Patrick的任何帮助

As stated by Jdweng there is not automatic method. 正如Jdweng所说,没有自动方法。 So I have to use cc.AxisX[0].Label[0] = "DDD";cc.AxisX[0].Label[1] = "EEE";cc.AxisX[0].Label[2] = "FFF" 所以我必须使用cc.AxisX [0] .Label [0] =“DDD”; cc.AxisX [0] .Label [1] =“EEE”; cc.AxisX [0] .Label [2] =“ FFF”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM