Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在Winform应用程序中获取条形图_C#_Winforms_Bar Chart - Fatal编程技术网

C# 无法在Winform应用程序中获取条形图

C# 无法在Winform应用程序中获取条形图,c#,winforms,bar-chart,C#,Winforms,Bar Chart,我试图在winform应用程序中显示数据库中的动态柱状图,但它没有出现,并在var p2=series.Points[arrlocationSTD]处异常给出参数错误当arrlocationSTD=1时。这是我的c代码 请帮我解决这个问题。 提前谢谢 您需要添加额外的处理,但以下内容可能会有所帮助 我强烈建议您在开始更改颜色属性等之前,让图表正确显示您的数据 void LoadBarChart(string qurystring) { String conn = Strings.Conn

我试图在winform应用程序中显示数据库中的动态柱状图,但它没有出现,并在
var p2=series.Points[arrlocationSTD]处异常给出
参数
错误
arrlocationSTD=1
时。这是我的c代码

请帮我解决这个问题。
提前谢谢

您需要添加额外的处理,但以下内容可能会有所帮助

我强烈建议您在开始更改颜色属性等之前,让图表正确显示您的数据

void LoadBarChart(string qurystring)
{
    String conn = Strings.ConnectionString; // You fill this in.

    Dictionary<String,int> callSummariesByTypeOfCall =
        new Dictionary<String,int>();

    MySqlConnection con = new MySqlConnection(conn);
    MySqlCommand comm = new MySqlCommand(qurystring, con);
    con.Open();
    MySqlDataReader dr = comm.ExecuteReader();

    // Get the data into a dictionary
    while (dr.Read())
    {
        String calltype = dr["TypeOfCall"].ToString();
        int summary = int.Parse(dr["Calls"].ToString(), CultureInfo.InvariantCulture);
        callSummariesByTypeOfCall[calltype] = summary;
    }

    // Do any other processing you need here

    // Bind the data onto the Series
    Series series = new Series
    {
        Name = "series2",
        IsVisibleInLegend = false,
        ChartType = SeriesChartType.Column
    };
    series.Points.DataBindXY(
        callSummariesByTypeOfCall.Keys,
        callSummariesByTypeOfCall.Values);
    barChart.Series.Add(series);
    barChart.Invalidate();

    pnlBar.Controls.Add(barChart);
}
void LoadBarChart(字符串qurystring)
{
String conn=Strings.ConnectionString;//请填写此项。
字典调用摘要按调用类型=
新字典();
MySqlConnection con=新的MySqlConnection(conn);
MySqlCommand comm=新的MySqlCommand(qurystring,con);
con.Open();
MySqlDataReader dr=comm.ExecuteReader();
//把数据输入字典
while(dr.Read())
{
字符串calltype=dr[“TypeOfCall”].ToString();
int summary=int.Parse(dr[“Calls”].ToString(),CultureInfo.InvariantCulture);
callSummariesByTypeOfCall[calltype]=摘要;
}
//您需要在这里进行其他处理吗
//将数据绑定到序列上
系列=新系列
{
Name=“series2”,
IsVisibleInLegend=false,
ChartType=SerieChartType.Column
};
series.Points.DataBindXY(
callSummariesByTypeOfCall.Keys,
callSummariesByTypeOfCall.Values);
条形图.系列.添加(系列);
barChart.Invalidate();
pnlBar.Controls.Add(条形图);
}

听起来像
系列。Points
集合包含一个或零个元素。在该行上放置断点,并使用手表查看该集合的内容。您只向该系列添加了一个断点。它的索引是0,而不是1。@HansPassant如果我有多个点,我总是需要以0、1、2等顺序添加或随机添加。如果点是列表或数组,它将使用基于零的索引进行排序。您可以将其更改为字典集合,然后它将使用您提供的“索引”作为键。例如,
专用字典点然后<代码>系列点.添加(arrlocationsSTD,intSTD)
@Mikeofst我已经用我的条形码的完整代码更新了我的帖子。请看一看,因为我完全没有办法解决这个问题。
Barchart.Series.DataBindXY
这个
DataBindXY
错误不存在。错过了
。更新了答案。你在这方面帮我吗?
void LoadBarChart(string qurystring)
{
    String conn = Strings.ConnectionString; // You fill this in.

    Dictionary<String,int> callSummariesByTypeOfCall =
        new Dictionary<String,int>();

    MySqlConnection con = new MySqlConnection(conn);
    MySqlCommand comm = new MySqlCommand(qurystring, con);
    con.Open();
    MySqlDataReader dr = comm.ExecuteReader();

    // Get the data into a dictionary
    while (dr.Read())
    {
        String calltype = dr["TypeOfCall"].ToString();
        int summary = int.Parse(dr["Calls"].ToString(), CultureInfo.InvariantCulture);
        callSummariesByTypeOfCall[calltype] = summary;
    }

    // Do any other processing you need here

    // Bind the data onto the Series
    Series series = new Series
    {
        Name = "series2",
        IsVisibleInLegend = false,
        ChartType = SeriesChartType.Column
    };
    series.Points.DataBindXY(
        callSummariesByTypeOfCall.Keys,
        callSummariesByTypeOfCall.Values);
    barChart.Series.Add(series);
    barChart.Invalidate();

    pnlBar.Controls.Add(barChart);
}