如何在C#的WinForm中制作饼状图和柱状图
1个回答
2016-04-15
展开全部
(1)设计时,在Form1上布置一个Chart控件,2个RadioButton
(2)窗体代码Form1.cs如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series[0].Points.AddXY(1, 10);
chart1.Series[0].Points.AddXY(2, 80);
chart1.Series[0].Points.AddXY(3, 55);
chart1.Series[0].Points.AddXY(4, 70);
chart1.Series[0].Points.AddXY(5, 92);
}
private void radioButton1_CheckedChanged(
object sender,
EventArgs e)
{
if (radioButton1.Checked)
{
chart1.Series[0].ChartType = SeriesChartType.Column;
}
else
{
chart1.Series[0].ChartType = SeriesChartType.Pie;
}
}
}
}
(3)运行
(2)窗体代码Form1.cs如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series[0].Points.AddXY(1, 10);
chart1.Series[0].Points.AddXY(2, 80);
chart1.Series[0].Points.AddXY(3, 55);
chart1.Series[0].Points.AddXY(4, 70);
chart1.Series[0].Points.AddXY(5, 92);
}
private void radioButton1_CheckedChanged(
object sender,
EventArgs e)
{
if (radioButton1.Checked)
{
chart1.Series[0].ChartType = SeriesChartType.Column;
}
else
{
chart1.Series[0].ChartType = SeriesChartType.Pie;
}
}
}
}
(3)运行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询