Kᴀτᴢ
Kᴀτᴢ

Reputation: 2176

Chart not showing first bar if series has only one point

I have a asp.net chart with int for Y values and DateTime for X values. If I have only one point in each series the first bar is not shown even though by debugging the datapoint is shown in the series.

If I have more than one point in each series all is working fine. The only thing which is different is that with one series the label for the date is not shown in the X axis, with two point in each series one date is shown in the axis. Don't know if this matters.

Series with one datapoint

enter image description here

Chart with one datapoint enter image description here

Series with two or more datapoints

enter image description here

Chart with two or more datapoints

enter image description here

UPDATE

This is my base table with one row (note: different values than in the question above):

enter image description here

I add the series for each "Gruppe" manually:

chart.Series.Add("Gruppe A");
chart.Series["Gruppe A"].ChartType = SeriesChartType.Column;
chart.Series["Gruppe A"].YValueMembers = "Gruppe A";
chart.Series["Gruppe A"].Color = System.Drawing.Color.FromArgb(0, 142, 207);
chart.Series["Gruppe A"].Label = "A:" + "#VALY";
chart.Series["Gruppe A"].XValueMember = "Datum";

Format of the AxisX:

chart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
chart.ChartAreas[0].AxisX.Interval = 1;
chart.ChartAreas[0].AxisX.LabelStyle.Format = "MMM/yy";
chart.ChartAreas[0].AxisX.Title = "Monat";

Chart with missing first month:

enter image description here

Upvotes: 0

Views: 819

Answers (1)

Kᴀτᴢ
Kᴀτᴢ

Reputation: 2176

Got the solution, set the AxisX.Intervalto 0 when there is only one row in the datasource:

if (dtChart.Rows.Count == 1) { chart.ChartAreas[0].AxisX.Interval = 0; } else { chart.ChartAreas[0].AxisX.Interval = 1; }

and set

chart.Series[0].IsXValueIndexed = true;

Upvotes: 0

Related Questions