I have a StackedBar which shows 5 values per bar, with the data value displayed in the middle of each block. So far, so good. However, when the value is zero, the value is still being displayed, which is messy when there are a lot of zeroes.
I would like to be able to hide the label for a zero. How can I do that?
(I presume I could do it the long way by reading the data row-by-row and building the graph step-by-step, but I would prefer to be able to just throw the query results at the control).
You can hide labels in the Customize event:
protected void SummaryChart_Customize(object sender, EventArgs e)
{
//hide label value if zero
foreach (System.Web.UI.DataVisualization.Charting.Series series in SummaryChart.Series)
{
foreach (System.Web.UI.DataVisualization.Charting.DataPoint point in series.Points)
{
if (point.YValues.Length > 0 && (double)point.YValues.GetValue(0) == 0)
{
point.IsValueShownAsLabel = false;
}
else
{
point.IsValueShownAsLabel = true;
}
}
}
}