C# 如何向VisualStudio项目添加不同的图表设计?
大家好,我有个问题,我需要为我的VisualStudio项目使用不同样式的图表类型,例如:饼图、柱状图。该项目的代码语言是c,我有一个html脚本。我的问题是:如何以及在哪里可以找到新图表并将其包含到我的项目中?以下函数定义图表类型等:C# 如何向VisualStudio项目添加不同的图表设计?,c#,html,visual-studio-2015,charts,C#,Html,Visual Studio 2015,Charts,大家好,我有个问题,我需要为我的VisualStudio项目使用不同样式的图表类型,例如:饼图、柱状图。该项目的代码语言是c,我有一个html脚本。我的问题是:如何以及在哪里可以找到新图表并将其包含到我的项目中?以下函数定义图表类型等: protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e) { Chart1.Visible = ddlCountries.Selected
protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
{
Chart1.Visible = ddlCountries.SelectedValue != "";
string query = string.Format("select shipcity, count(orderid) from orders where shipcountry = '{0}' group by shipcity", ddlCountries.SelectedValue);
DataTable dt = GetData(query);
string[] x = new string[dt.Rows.Count];
int[] y = new int[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToInt32(dt.Rows[i][1]);
}
Chart1.Series[0].Points.DataBindXY(x, y);
Chart1.Series[0].ChartType = SeriesChartType.Pie;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
Chart1.Legends[0].Enabled = true;
}
我之所以使用此函数代码,是因为它可以帮助您理解我:
祝您愉快您只需根据需要更改图表类型即可。如果希望相同的数据以不同的样式显示,甚至不需要将新数据点绑定到序列
这里有一个小程序来演示这一点。它有一个SerieChartTypes列表,绑定到一个组合框,您可以在其中选择样式:
List<SeriesChartType> typeList = new List<SeriesChartType>() {
SeriesChartType.Pie,
SeriesChartType.Line,
SeriesChartType.Bar };
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = typeList;
}
您想在同一个图表中显示不同的样式吗?或者你有多个图表对象?@MongZhu如果可能的话,我需要在同一个图表中使用不同的样式:@MongZhu谢谢你的帖子:但我不明白它是如何改变图表的视觉效果的?我的意思是我需要更吸引人的图表:它将折线图更改为条形图等等。你所说的更有吸引力的图表是什么意思?
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex >= 0)
{
SeriesChartType type = typeList[comboBox1.SelectedIndex];
List<int> values = new List<int> { 1, 2, 3, 3, 3, 3, 4, 5, 6, 6, 6, 4, 4, 3, 2, 2, 1, 1 };
chart1.Series[0].Points.DataBindY(values);
chart1.Series[0].ChartType = type;
}
}