2
votes

I'm building some charts showing hourly aggregate totals with an overlay of live data over the same time period:

alt text
(source: riotgibbon.org)

By default, MSChart positions the vertical bar in the centre of the datapoint, so you can see that the left-half of the first entry at midnight is missing, and there's a gap on the right-hand side at 23:00.

Is it possible to nudge the bars along a bit, so they start at their datapoint, rather than being centred upon it?

Thanks

Toby

1
just noticed that @Glorfindel fixed the image via the WayBack machine - good job!TobyEvans

1 Answers

0
votes

An ever so slight 'dirty' workaround is to add 0.5 to the X position of each datapoint in your column chart.

chart1.Series[0].Points.Add(new DataPoint(x + 0.5, y))

A non dirty approach that I recommend / would use - you could set the x-axis minimum to -0.5

chart1.ChartAreas.[0].AxisX.Minimum = -0.5;

This may be the only way to have the desired effect.

If this causes your axis labels, major grid, major ticks, or interval to be shifted in an undesirable manner, see the code below for an example of how to fix it.

chart1.ChartAreas[0].AxisX.LabelStyle.IntervalOffset = 0.5;
chart1.ChartAreas[0].AxisX.MajorGrid.IntervalOffset = 0.5;
chart1.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset = 0.5;