GetReQ GetReQ - 1 year ago 96 Question

Display x-axis label at certain data-points in mschart

I'm trying to plot a normal distribution curve (as a SeriesChartType.Spline) with a selected items location on that curve. My x-axis is a little messy so I'm trying to tidy it up but I can't figure a way to show the axis label at specific locations.

I'd like to show the value at {x(0), x(mean), x(n)} and also the x-axis value of the selected item's data-point on the curve.

enter image description here

I've tried playing with the


but I don't necessarily have a standard interval range.

Is there a way I can display the x-axis label only at specified data points?

Answer Source

You have a choice of either

  • Replacing the normal labels by CustomLabels. They are a bit tricky since you can't set their position. Instead you need two positions (FromPosition and ToPosition) to declare the range where the CustomLabel shall be centered. Note that once you use CustomLabels no normal ones will show.

  • Or you can add TextAnnotations. You can set AnchorX to the value you want and the Y position to the minimum of your y-values. Getting these right is also a little tricky, involving the axes of the Annotation and also the IsSizeAlwaysRelative which should be false.

  • Or you could code the Pre- or PostPaint events and Graphics.DrawString or TextRenderer.DrawText the text you want using the ValueToPixelPosition axes functions to get the coordinates. This may actually be the easiest to do..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download