0

I'm creating column charts using System.Web.UI.DataVisualization.Charting which have a variable number of series and X datapoint values.

I can turn value labels on using:

myChart.Series[0].IsValueShownAsLabel = true;

Depending on how many series and datapoints there are however, these labels can become unreadable. Is there a way to have value labels but only if they are readable?

A thought I had was along the lines of:

int datapointsCount = ?????;
int labelPixelSize = 15;
int chartPixelSize = ?????;

if ((myChart.Series.Count * datapointsCount * labelPixelSize) > chartPixelSize) {
    foreach (Series mySeries in myChart.Series) {
        mySeries.IsValueShownAsLabel = false;
    }
}

This is pretty messy and far from ideal however.

Thanks!! ;)

Akaoni
  • 941
  • 1
  • 10
  • 13

1 Answers1

0

Enable the Smart Label feature.

myChart.Series[0].SmartLabelStyle.Enabled = true;

The control initially tries to draw the overlapping label near the data point itself. If this does not work, it draws the label in the next available free space and draws a line connecting the label with the data point.

Joe Vi
  • 473
  • 4
  • 10