111,097
社区成员




private void LoadForm()
{
chart1.Series.Clear();
ChartHelper.AddSeries(chart1, "折线图", SeriesChartType.Line, Color.Red, Color.Red);
ChartHelper.SetTitle(chart1, "折线图", new Font("微软雅黑", 12), Docking.Bottom, Color.Black);
ChartHelper.SetStyle(chart1, Color.Transparent, Color.White);
ChartHelper.SetLegend(chart1, Docking.Top, StringAlignment.Center, Color.Transparent, Color.Black);
ChartHelper.SetXY(chart1, "日期", "值", StringAlignment.Far, Color.Black, Color.Black, AxisArrowStyle.None, 1, 2);
//网格这是
ChartHelper.SetMajorGrid(chart1, Color.Gray, 1, 0.5, ChartDashStyle.Dash, ChartDashStyle.NotSet);
//标记点设置
chart1.Series[0].MarkerSize = 8;//标记点大小
chart1.Series[0].MarkerStyle = MarkerStyle.Circle; //标记点类型
//提示
chart1.Series[0].ToolTip = "线:#SER\nx: #VALX\ny:#VALY";
//Y轴最大值和最小值
chart1.ChartAreas[0].AxisY.Maximum = 22;
chart1.ChartAreas[0].AxisY.Minimum = 18;
chart1.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.None; //箭头样式
//绑定值
chart1.Series["折线图"].Points.DataBind(listDemo.AsEnumerable(), "StartDate", "ValueInt", "");
//设置警戒线
double max = 20;
StripLine stripMax = new StripLine();
//stripMax.Text = string.Format("最大:{0:F}", max);//展示文本
stripMax.Font = new Font("宋体", 20);//文本字体
stripMax.BackColor = Color.FromArgb(208, 109, 106);//背景色
stripMax.Interval = 0;//间隔
stripMax.IntervalOffset = max;//偏移量
stripMax.StripWidth = 0.01;//线宽
// stripMax.ForeColor = Color.White;//前景色
//stripMax.TextAlignment = StringAlignment.Near;//文本对齐方式
//
chart1.ChartAreas[0].AxisY.StripLines.Add(stripMax);//添加到ChartAreas中
stripMax = new StripLine();
stripMax.IntervalOffset = max + 0.5;
chart1.ChartAreas[0].AxisY.StripLines.Add(stripMax);//添加到ChartAreas中
}
List<Demo> listDemo = new List<Demo>();
private void InitData()
{
List<double> y = new List<double>() { 18.5, 19, 19.5, 20, 20.5, 21, 21.5 };
Random random = new Random();
for (int i = 0; i < 12; i++)
{
Demo demo = new Demo();
int index= random.Next(y.Count());
demo.ValueInt = y[index];
demo.StartDate = DateTime.Now.AddDays(i);
if (i == 3)
{
demo.ValueInt = 1;
}
listDemo.Add(demo);
}
//绑定数据
}