我正在创建一个小程序,它通过图表按月显示我们的总销售额,我需要通过我的 SQL 响应名称(2012'7、2012'8、2012 调用 X 轴点(1、2、3、4、5) '9),但找不到如何做到这一点。
代码:
sqlQuery = "SELECT YEAR(`importdate`) as 'Year', MONTH(`importdate`) as 'Month', SUM(`price`) as 'Sum' FROM `wagon` GROUP BY MONTH(`importdate`), YEAR(`importdate`) ORDER BY YEAR(`importdate`), MONTH(`importdate`) ASC LIMIT 12";
MySqlConnection sqlConnection = new MySqlConnection(sqlParams);
MySqlCommand sqlCommand = new MySqlCommand(sqlQuery, sqlConnection);
chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gainsboro;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gainsboro;
try
{
sqlConnection.Open();
MySqlDataReader sqlReader = sqlCommand.ExecuteReader();
if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
string Sum = sqlReader["Sum"].ToString();
if (Sum.Contains(",")) Sum = Sum.Replace(",", ".");
string serieName = "Series1";
// string serieName = sqlReader["Year"].ToString() + '\'' + sqlReader["Month"].ToString();
// chart1.Series.Add(sqlReader["Year"].ToString() + '\'' + sqlReader["Month"].ToString());
// chart1.Series[serieName].ChartArea = "ChartArea1";
chart1.Series[serieName].Points.AddY(Sum);
chart1.Series[serieName].ChartType = SeriesChartType.Line;
chart1.Series[serieName].IsValueShownAsLabel = true;
//sqlReader["Year"].ToString() + '"' + sqlReader["Month"].ToString()
}
}
}