jeudi 31 mars 2016

ASP Chart X axis minimum and maximum in months

Good Day, I have an ASP chart with dates bound to the X axis. And my [SELECT] statement reads the last 12 months from the database. Problem is, if there's no data for that month it doesn't show up as an entry in my Database. Which means the last 12 months could be "March, Feb, Nov, Aug ...." (Notice the missing months). What I need is for the X-Axis to always show the last 12 months only, even if no data for a month I don't mind it be blank. Here is the code where I bind the data to the chart.

Global.dbConnection.Open();
Global.GeneralChartQuery = "SELECT [PO Date], [Price Trend] FROM (SELECT TOP 12 [PO Date], [Price Trend] From [Report 1 - Monthly Weighted] ORDER BY [PO Date] DESC) SUB ORDER BY [PO Date] ASC";
OleDbCommand GeneralCommand = new OleDbCommand(Global.GeneralChartQuery, Global.dbConnection);
GeneralCommand.CommandType = CommandType.Text;
OleDbDataAdapter GeneralList = new OleDbDataAdapter(GeneralCommand);
DataTable GeneralList2 = new DataTable();
GeneralList.Fill(GeneralList2);
Global.dbConnection.Close();
Chart1.DataSource = GeneralList2;
Chart1.Series[0].XValueMember = "PO Date";
Chart1.Series[0].YValueMembers = "Price Trend";
Chart1.DataBind();

Select statement is included in the code. Could you please suggest a way to help me show only the last actual 12 months, not the database's last 12 months in this chart?




Aucun commentaire:

Enregistrer un commentaire