图表:在时间图中将布尔标志显示为实心矩形(而不是线条) [英] Chart : displaying boolean flags in a time plot as filled rectangles (instead of as lines)

查看:77
本文介绍了图表:在时间图中将布尔标志显示为实心矩形(而不是线条)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WinForms中的C#图表使用折线图表类型实时绘制各种变量。这对于模拟值效果很好,但是对于开/关标志来说却不理想。



我想绘制多个标记作为水平条,当值为' 1,并清除值何时为 0。



在从从头开始,您对我如何利用图表对象的任何功能来更有效地实现此功能有任何建议吗?



编辑:我正在玩
编辑2:这没有用,因为Area类型的区域总是从图表的底部开始,隐藏其他行,我现在正在尝试Range列类型

解决方案

我知道了:
:PointWidth不受限制到2。)



B)绘制(对每个新数据点执行一次):

  baseLine--; 
int barHeight = flagHigh吗? 1:0;
plotChart.Series [chanNo] .Points.AddXY(pointX,baseLine,baseLine + barHeight);

flagHigh是一个布尔值,等于正在监视的标记。



baseLine为每个跟踪递减。在上面的示例中,baseLine从4开始,递减至0。



请注意,对于每个数据点,RangeColumn都需要2个 Y值:矩形的底部,顶部为一个;在代码中,我将底部Y设置为用于该特定标志的行的底部,并将顶部Y设置为底部上方的1,以使我的高度为1。


I use the C# Chart in WinForms to plot a variety of variables in real time using the "line" chart type. That works well for analog values, but it's less than ideal for on/off flags.

I'd like to plot multiple flags as horizontal bars that are filled when the value is '1" and clear when the value is '0'.

Before I start coding a solution from scratch, do you have any suggestion on how I could take advantage of any features of the "chart" object to implement this more effectively?

EDIT: I am playing with the Area type, and it seems to be promising. EDIT 2: That didn't work, because the area in the Area type always starts at the bottom of the chart, hiding the other rows. I am now trying the Range Column type

解决方案

I got it:

It turned out to actually be pretty easy; I used the Range Column type.

A) Set-up (done once):

plotChart.Series[chanNo].ChartType = SeriesChartType.RangeColumn;
plotChart.Series[chanNo].CustomProperties = "PointWidth=" + noOfFlags;

PointWidth is required to set the relative width of each rectangle so that it fills the entire width of one data point (if too small, there are gaps in the horizontal bar; if too large, there is overlap). noOfFlags is the number of flags shown (in the example shown above, noOfFlags = 4). (By the way the MSDN documentation is wrong: PointWidth is not limited to 2.)

B) Plotting (done for each new data point):

baseLine--;
int barHeight = flagHigh ? 1 : 0;
plotChart.Series[chanNo].Points.AddXY(pointX, baseLine, baseLine + barHeight);

flagHigh is a bool that is equal to the flag being monitored.

baseLine is decremented for each trace. In the example above, baseLine starts at 4, and is decremented down to 0.

Note that for each data point, RangeColumn requires 2 "Y" values: one for the bottom of the rectangle, one for the top; in the code, I set the bottom Y to the bottom of the row that I use for that particular flag, and the top to 1 above the bottom, to give me a height of 1.

这篇关于图表:在时间图中将布尔标志显示为实心矩形(而不是线条)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆