C#中chart控件怎么使用datasource来绘制曲线图?能否给个例子

2024-11-13 12:45:43
推荐回答(2个)
回答1:

chart1.ChartAreas.Clear(); chart1.Series.Clear(); chart1.Annotations.Clear(); chart1.Legends.Clear(); chart1.Titles.Clear(); Title t = new Title("委案情况分析"); t.Alignment = ContentAlignment.MiddleLeft; t.TextOrientation = TextOrientation.Stacked; t.IsDockedInsideChartArea = false; t.Font = new System.Drawing.Font("黑体", 20, FontStyle.Bold); chart1.Titles.Add(t); ChartArea c1 = new ChartArea("C1"); c1.AxisX.IntervalType = DateTimeIntervalType.Days;//X轴以天数为间隔 c1.AxisX.Interval = 1; //X轴刻度的间隔为1 c1.AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount; c1.AxisX.MajorGrid.Enabled = false; //不显示网格线 c1.AxisY.MajorGrid.Enabled = false; chart1.ChartAreas.Add(c1); Series s1 = new Series("S1"); s1.ChartType = SeriesChartType.Spline; //画表类型 Random rnd = new Random(); for (int i = 0; i < 10; i++) { DateTime date = DateTime.Now.AddDays(i); DataPoint d = new DataPoint(); //要显示的数据 d.XValue = date.ToOADate(); //X轴的值,DataPoint只接收double类型 d.YValues[0] = rnd.NextDouble(); //Y轴的值 s1.Points.Add(d); } chart1.Series.Add(s1);

回答2:

你邮箱多少