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# 条形图ASP.net C的输入字符串格式不正确_C#_Asp.net_Charts - Fatal编程技术网

C# 条形图ASP.net C的输入字符串格式不正确

C# 条形图ASP.net C的输入字符串格式不正确,c#,asp.net,charts,C#,Asp.net,Charts,我试图使用图表显示摘要页面,但似乎有错误,我不知道如何解决它。当我运行SQL语句时,数据将显示如下 |总计|学生响应| |2 | A| |0 | B| |1 | C| |3 | D| using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using MySql.Data.My

我试图使用图表显示摘要页面,但似乎有错误,我不知道如何解决它。当我运行SQL语句时,数据将显示如下

|总计|学生响应| |2 | A| |0 | B| |1 | C| |3 | D|

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
using System.Web.UI.DataVisualization.Charting;

public partial class Teacher_Summary : System.Web.UI.Page
{
    MySqlConnection myConn;
    protected void Page_Load(object sender, EventArgs e)
    {
        chartQn1.Visible = false;
        int quiz = (int)Session["topicID"];
        string question1 = (string)Session["question1"];

        myConn.Open();
        DataTable dt = new DataTable();
        string populateData = "select count(studentResponse) as Total, studentResponse from result where quizID = '" + quiz + "' and questionID = '" + question1 + "' group by studentResponse";
        MySqlDataAdapter sda = new MySqlDataAdapter(populateData, myConn);
        sda.Fill(dt);
        myConn.Close();

        string[] x = new string[dt.Rows.Count];
        double[] y = new double[dt.Rows.Count]; 
        for (int i = 0; i < dt.Rows.Count; i++) 
        {
            x[i] = dt.Rows[i][0].ToString();
            y[i] = Convert.ToDouble(dt.Rows[i][1]); // <-- this is the error
        }
        chartQn1.Series[0].Points.DataBindXY(x, y);

        chartQn1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Column;

    }
    protected void btnDone_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Teacher/Questions.aspx");
    }
    protected void btnReveal_Click(object sender, EventArgs e)
    {
        btnReveal.Visible = false;
        chartQn1.Visible = true;
    }
    protected void chartQn1_Load(object sender, EventArgs e)
    {

    }
}
那我该怎么做呢? 我收到的错误是Y的输入错误。

检查您的类型

y[i] = Convert.ToDouble(dt.Rows[i][1]); 

您试图将字符串“A”转换为double和其他“B”、“C”、“D”

首先,我想您可能已经改变了顺序,请尝试x[I]=dt.Rows[I][1];和y[i]=Convert.ToDoubledt.Rows[i][0];。第二,考虑使用方法,它增加错误检查,并确保如果代码无效,则代码不会崩溃。