I have some code here for a chart in my report which resides in the NeedDataSource for the chart. Everything's working great "except one line" which should change the "stacked bar 100" chart Y labels to percentages (I have four databound series which show fine on the chart otherwise):
For ThisOne As Integer = 0 To 4
Me.Chart1.Series(ThisOne).Name = Me.ReportParameters("DataTitle" + (ThisOne + 1).ToString).Value
Me.Chart1.Series(ThisOne).Appearance.LabelAppearance.LabelLocation = Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Inside
Me.Chart1.Series(ThisOne).Appearance.LabelAppearance.Position.AlignedPosition = Charting.Styles.AlignedPositions.Center
Me.Chart1.Series(ThisOne).Appearance.TextAppearance.TextProperties.Color = Color.Black
Me.Chart1.Series(ThisOne).Appearance.Shadow.Blur = 4
Me.Chart1.Series(ThisOne).Appearance.Shadow.Distance = 2
Me.Chart1.Series(ThisOne).Appearance.Shadow.Position = Charting.Styles.ShadowPosition.BottomRight
Me.Chart1.Series(ThisOne).DefaultLabelValue = "#%"
I expected from the documentation and forums that the "DefaultLabelValue" line would change the stacked bar labels to percentages but it does not for me. I can set the DefaultLabelValue property at design time and all looks dandy, however, that property gets wiped out at the time of the NeedDataSource, hence my feeble attempt here to make things right...
Please point me to the errors of my ways so I can wrap up this chart!
5 Answers, 1 is accepted
If you set the DataLabelsColumn property in the report designer, please remove it. This interferes with DefaultLabelValue which needs the value from the DataYColumn (through the #Y token) as a numeric value, so that the format is applied. DataLabelsColumn is intended for cases, where one would need a string label, taken from a completely different column.
the Telerik team
You've bound the chart directly by using the DataSource property, however this way chart series and items are created automatically and you do not have control over them. The proper way to do this would be to bind the chart through the designer by using our Data Source Components. This way you would create the series from the series collection, specify the DataYColumn/DataLabelsColumn for the series and of course control the LabelAppearance properties as well. You can change the position of the item label from Series --> Appearance --> LabelAppearance --> LabelLocation="Inside" and Series --> Appearance --> LabelAppearance --> Position --> AlignedPosition="Center".
the Telerik team