0
votes

I created a chart containing two series which shows values (AXIS Y - int) of two distribution channels ( SERIES A and B) day by day (AXIS X - datetime) . All data comes from datatable which comes from external db. Until I present data between Monday and Saturday all go well. The problem appears during weekend. It happens that there is no data on channel A on Sunday. In such a case chart with bars get messed. There is no Sunday bar at all ( two Mondays instead of) but data of channel A are shifted one day back.
Below code I wrote:

public Chart DrawBar(OracleConnection oc, Chart ch)
{
    DataTable dt = GenerateData(oc, queryBar());
    Chart chart1 = ch;
    foreach (string s in channel)
    {
        chart1.Series.Add(s);
        chart1.Series[s].XValueType = ChartValueType.DateTime;
        chart1.Series[s].YValueType = ChartValueType.Double;
        chart1.Series[s].ChartType = SeriesChartType.StackedColumn;
    }
    foreach (DataRow row in dt.Rows)  
    {
        string series = row["SOURCE"].ToString();
        DateTime X = (DateTime)row["DATA"];
        String Y = row["HOWMUCH"].ToString();
        chart1.Series[series].Points.AddXY(X.ToShortDateString(), Convert.ToDouble(Y));
        chart1.Series[series].IsValueShownAsLabel = true;
    }
    return chart1;
}

I found some info about Series.IsXValueIndexed as well as Chart1.DataManipulator.InsertEmptyPoints but I can't understand how it could be used in my code.

1

1 Answers

0
votes

The problem is that you're converting the DateTime to a string when adding the points. Leave it as a DateTime and it will deal with empty points just fine:

DateTime X = (DateTime)row["DATA"];
String Y = row["HOWMUCH"].ToString();
chart1.Series[series].Points.AddXY(X, Convert.ToDouble(Y));

Also, if you know that your column "HOWMUCH" is a double, you can do this instead, which is a bit cleaner:

double Y = row.Field<double>("HOWMUCH");
chart1.Series[series].Points.AddXY(X, Y);