Wednesday, October 05, 2011 11:45 AM
How do I add a horizontal line to my Bar Chart at point 0 on Y-Axis?
Thursday, October 06, 2011 12:45 AM
do you mean a custom drawn line thats independend from the charts data? You could handle the paint events for that (PostPaint after painting the Series)
see http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/6a7ec829-2e65-4977-86a5-d94fb3c9d670 for an example of a custom drawn vertical line that interacts with the arrow keys (ctrl must be pressed also).
- Edited by Thorsten GuderaMicrosoft Community Contributor Thursday, October 06, 2011 12:47 AM
Thursday, October 06, 2011 8:53 AM
I just want the gridline to appear at point 0.
AxisY.MajorGrid.Enabled = true
but that drew gridlines for all points. Is it possible just to set 1 gridline?
- Edited by obrienkev Thursday, October 06, 2011 8:53 AM
Thursday, October 06, 2011 10:24 AMModerator
I explain four different ways to show a line on a chart in this thread.
Here's number five that may work for your particular case.
5) Adjust the MajorGrid.Interval and IntervalOffset to get a single line at position 0 (assuming AxisY.Minimum is a negative value)
'RecalculateAxesScale to get the actual values for the automatically calculated axis.min & max. chart1.ChartAreas(0).RecalculateAxesScale() 'Set the majorgrid interval to something *big* for the gridline to only show once. chart1.ChartAreas(0).AxisY.MajorGrid.Interval = Math.Abs(chart1.ChartAreas(0).AxisY.Minimum) + Math.Abs(chart1.ChartAreas(0).AxisY.Maximum) 'Set the majorgrid interval offset so that the first gridline appears at position 0. chart1.ChartAreas(0).AxisY.MajorGrid.IntervalOffset = Math.Abs(chart1.ChartAreas(0).AxisY.Minimum)
BTW, care to report back on this thread and this one? Did you find a solution for the questions you asked?
- Edited by siplaModerator Thursday, October 06, 2011 10:28 AM btw
Friday, October 07, 2011 11:15 AM
// add horizontal line at point 0 StripLine stripLine3 = new StripLine(); // Set threshold line so that it is only shown once stripLine3.Interval = 0; // Set the threshold line to be drawn at the calculated mean of the first series stripLine3.IntervalOffset = 0; stripLine3.BackColor = Color.DarkGreen; stripLine3.StripWidth = 10; // Add strip line to the chart myChart.ChartAreas.AxisY.StripLines.Add(stripLine3);
- Marked As Answer by obrienkev Friday, October 07, 2011 11:15 AM