添加水平线以图在C# [英] Add horizontal line to chart in C#
问题描述
我使用的是 System.Windows.Forms.DataVisualization.Chart
来绘制一些X,Y分散数据,如:
chart1.Series [系列2] Points.AddXY(字符串X,doubleY);
-
我想添加到图表的水平线上,平均形式为y =常数。 我怎样才能做到这一点?请注意,x轴是一个字符串
-
其实,X轴是时间(HH:MM:SS)。我将其转换为字符串阴谋,因为如果我使用DateTime格式图表的X轴(XValueType)它不显示的秒数。 我可以纠正的,以显示秒,所以我可以直接打印x作为日期时间和y为双?
对于第2点,您仍然可以设置 XValueType
到日期时间
,但在适当的格式 LabelStyle
。
chart1.Series [SeriesName] .XValueType = ChartValueType.DateTime;
//使用所需要的格式。我用下面的格式为例。
chart1.ChartAreas [ChartName] .AxisX.LabelStyle.Format =DD / MM / YY HH:MM:SS;
有关问题1,添加一个带状线
的chartarea的Y轴。
带状线带状线=新的带状线();
stripline.Interval = 0;
y轴的stripline.IntervalOffset =平均值;例如:35
stripline.StripWidth = 1;
stripline.BackColor = Color.Blue;
chart1.ChartAreas [ChartAreaName] .AxisY.StripLines.Add(带状线);
I am using a System.Windows.Forms.DataVisualization.Chart
to plot some x,y scatter data, like this:
chart1.Series["Series2"].Points.AddXY(stringX, doubleY);
I would like to add to that chart an horizontal line with an average of the form y = constant. How can I do this? Please, notice that the x axis is a string
Actually, the x axis is the time (hh:mm:ss). I am converting it to string to plot it because if I use the DateTime format for the x axis (XValueType) of the chart it doesn't show the seconds. Can I correct that to show the seconds so I can plot directly x as DateTime and y as double?
For point 2, you can still set the XValueType
to DateTime
but with proper format in LabelStyle
.
chart1.Series[SeriesName].XValueType = ChartValueType.DateTime;
// Use the required format. I used the below format as example.
chart1.ChartAreas[ChartName].AxisX.LabelStyle.Format = "dd/mm/yy hh:mm:ss";
For point 1, add a StripLine
to the Y-Axis of the chartarea.
StripLine stripline = new StripLine();
stripline.Interval = 0;
stripline.IntervalOffset = average value of the y axis; eg:35
stripline.StripWidth = 1;
stripline.BackColor = Color.Blue;
chart1.ChartAreas[ChartAreaName].AxisY.StripLines.Add(stripline);
这篇关于添加水平线以图在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!