我有一个绘制折线图的功能,如下所示。数据点是从MySQL表中获得的。但是,如何在x轴1,2,3,4 ......
中对每个数据点进行编号在下面的示例中,查询返回两个结果,图表显示两个点,因此图表应在轴上标记为1和2。
编辑:初始问题已解决。但是,对于上面的示例,有2个数据点,但最大x值为3.有没有办法将最大x值设置为等于数据点数?
protected void chart(int moduleID)
{
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
MySqlConnection conn = new MySqlConnection(connStr);
string comm = "SELECT * FROM scores WHERE test_id=0 AND module_id=@ModuleID AND user_id=@UserID";
MySqlCommand mySqlCommand = new MySqlCommand(comm, conn);
mySqlCommand.Parameters.Add(new MySqlParameter("@ModuleID", moduleID));
mySqlCommand.Parameters.Add(new MySqlParameter("@UserID", Session["UserID"]));
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(mySqlCommand);
DataTable ds = new DataTable();
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = 1;
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.Title = "attempt no.";
Chart1.ChartAreas["ChartArea1"].AxisY.Minimum = 0;
Chart1.ChartAreas["ChartArea1"].AxisY.Maximum = 100;
Chart1.ChartAreas["ChartArea1"].AxisY.Title = "%";
Chart1.ChartAreas["ChartArea1"].AxisY.TextOrientation = TextOrientation.Horizontal;
try
{
conn.Open();
dataAdapter.Fill(ds);
if (ds.Rows.Count > 0)
{
Chart1.DataSource = ds;
Chart1.Series["Series1"].YValueMembers = "score";
Chart1.DataBind();
}
else
{
Chart1.Visible = false;
lblError2.Text = "No results found.";
}
}
catch
{
lblError.Text = "Database connection error. Unable to obtain data at the moment.";
}
finally
{
conn.Close();
}
}
答案 0 :(得分:1)
有问题:
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
您已停用轴标签