简体   繁体   English

固定长度的 MSChart X 轴

[英]MSChart X axis with fixed length

I want to show values (y axis) in a range of hours (x axis) from 7am to 12m, the X axis should show always that range even if I have no value for a specific hour.我想显示从早上 7 点到 12m 的小时范围(x 轴)内的值(y 轴),即使我没有特定小时的值,X 轴也应该始终显示该范围。 Here an example to clarify that:这里有一个例子来说明:

X=7, Y (no value) X=7, Y(无值)

X=8, Y (no value) X=8, Y(无值)

X=9, Y=24 X=9, Y=24

X=10, Y=60 X=10, Y=60

X=11, Y=30 X=11, Y=30

X=12, Y=80 X=12, Y=80

To accomplish that, I filled out the empty Y values with zeros, so I was able to show the values from 7-12, otherwise I gonna show only the values from 9-12.为此,我用零填充了空的 Y 值,因此我能够显示 7-12 的值,否则我将只显示 9-12 的值。

But now, it is causing me problems.但现在,它给我带来了问题。 So my question is, is there any way that I can keep showing the range from 7-12 even if I have no Y values in the beginning like the above example?所以我的问题是,有没有什么方法可以让我继续显示 7-12 的范围,即使我在开头没有 Y 值,就像上面的例子一样?

I use: SeriesChartType.Column;我使用:SeriesChartType.Column;

Here is the solution:这是解决方案:

chart1.ChartAreas[0].AxisX.Minimum = 7;
chart1.ChartAreas[0].AxisX.Maximum = 12;

Thanks谢谢

In addition to the previous answer from @Somebody: if you don't have a value for a certain point, you must put a "NaN" value there, anyway if you want that point to be rendered:除了@Somebody 的先前回答:如果您没有某个点的值,则必须在其中放置一个“NaN”值,无论如何如果您希望呈现该点:

double emptyYvalue = double.NaN;

Use this value for the Y value in your data binding structure.将此值用作数据绑定结构中的 Y 值。

Not sure I understand the question fully, but first you should use DateTime types for your chart not ints, then Date.Hour.不确定我是否完全理解这个问题,但首先你应该为你的图表使用 DateTime 类型而不是整数,然后是 Date.Hour。 The wonderful MSChart will then fill in the x-axis gaps and this also enables you to use all the chart's datetime functions to assign ranges etc.然后,精彩的 MSChart 将填充 x 轴间隙,这也使您能够使用图表的所有日期时间函数来分配范围等。

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

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