我有一个带有图表的C#应用程序,该图表显示了每月的交易量。但我想显示当前年份的月份,而不显示过去一年的交易。
这是我要实现的方案,我想在图表中显示2020年7月1日的值,而不显示2019年7月7日或去年的所有交易。
我附上了电费单作为参考
public void LoadChart1()
{
con.conDB.Open();
sda = new MySqlDataAdapter("SELECT Monthname(sdate) as month, IFNULL(sum(total),0.0) as total from tblcart where status like 'Sold' GROUP BY Month(sdate)", con.conDB);
ds = new DataSet();
sda.Fill(ds, "Sales");
chart2.DataSource = ds.Tables["Sales"];
Series series1 = chart2.Series["Series1"];
series1.ChartType = SeriesChartType.Bar;
series1.Name = "SALES";
var chart = chart2;
chart.Series[series1.Name].XValueMember = "month";
chart.Series[series1.Name].YValueMembers = "total";
chart.Series[0].IsValueShownAsLabel = true;
//chart.Series[0].LegendText = "#";
con.conDB.Close();
}
答案 0 :(得分:0)
我不确定您到底想要什么。但是,如果您只想要过去一年中的值,则将其添加到您的SQL语句where子句中:
and sdate >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
如果您只想要同一日历年(例如2020年)内的值,则添加以下内容:
and YEAR(sdate) = YEAR(NOW())