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 = "#%"
Next
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!
Thanks,
Steve
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.
Best wishes,
Steve
the Telerik team

Steve

Unable to change LabelLocation to inside
I have numerous stacked bar charts that I need to make readable. I have tried positioning the label inside
as
well
out
setting to auto. The problem
is
that when a number
is
very small it isn't very readable. I have a live date next week and need a solution.
Telerik.Reporting.Processing.Chart chart = sender
as
Telerik.Reporting.Processing.Chart;
DataTable table =
new
DataTable();
table.Columns.Add(
"PRM"
,
typeof
(
string
));
table.Columns.Add(
"Argatroban"
,
typeof
(
string
));
table.Columns.Add(
"Arixtra"
,
typeof
(
string
));
table.Columns.Add(
"Arranon"
,
typeof
(
string
));
table.Columns.Add(
"Arzerra"
,
typeof
(
string
));
table.Columns.Add(
"Benlysta"
,
typeof
(
string
));
table.Columns.Add(
"Bexxar"
,
typeof
(
string
));
table.Columns.Add(
"Hycamtin ora"
,
typeof
(
string
));
table.Columns.Add(
"Promacta"
,
typeof
(
string
));
table.Columns.Add(
"Tykerb"
,
typeof
(
string
));
table.Columns.Add(
"Votrient"
,
typeof
(
string
));
table.Columns.Add(
"General"
,
typeof
(
string
));
table.Columns.Add(
"Other"
,
typeof
(
string
));
table.Rows.Add(
new
object
[] {
"Test 1"
, 22, 5, 303, 165, 77, 32, 55, 99, 233, 111, 48, 18 });
table.Rows.Add(
new
object
[] {
"Test 2"
, 202, 50, 33, 6, 177, 2, 15, 44, 233, 11, 4, 108 });
chart.DataSource = table;
chart1.ChartTitle.TextBlock.Text =
"TEST PRM Activity for: "
+ ReportSessionData.UserName;
Palette palette =
new
Palette(
"MyPalette"
);
palette.Items.Add(
new
PaletteItem(Color.LightSkyBlue, Color.LightSkyBlue));
palette.Items.Add(
new
PaletteItem(Color.CadetBlue, Color.CadetBlue));
palette.Items.Add(
new
PaletteItem(Color.Blue, Color.Blue));
palette.Items.Add(
new
PaletteItem(Color.LawnGreen, Color.LawnGreen));
palette.Items.Add(
new
PaletteItem(Color.LightCoral, Color.LightCoral));
palette.Items.Add(
new
PaletteItem(Color.MediumVioletRed, Color.MediumVioletRed));
palette.Items.Add(
new
PaletteItem(Color.MistyRose, Color.MistyRose));
palette.Items.Add(
new
PaletteItem(Color.LimeGreen, Color.LimeGreen));
palette.Items.Add(
new
PaletteItem(Color.MediumSpringGreen, Color.MediumSpringGreen));
palette.Items.Add(
new
PaletteItem(Color.Green, Color.Green));
palette.Items.Add(
new
PaletteItem(Color.DarkGreen, Color.DarkGreen));
palette.Items.Add(
new
PaletteItem(Color.ForestGreen, Color.ForestGreen));
chart1.CustomPalettes.Add(palette);
chart1.SeriesPalette =
"MyPalette"
;
chart1.Series[0].PlotArea.XAxis.DataLabelsColumn =
"PRM"
;
chart1.Series[0].Appearance.LabelAppearance.LabelLocation = Telerik.Reporting.Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Inside;
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".
Regards,
Steve
the Telerik team

private void chart1_NeedDataSource(object sender, EventArgs e)
{
InputVariables iv = new InputVariables();
iv.RptStart = ReportSessionData.StartDate;
iv.RptEnd = ReportSessionData.EndDate;
iv.ProductName = ReportSessionData.ProductName;
iv.PRMID = ReportSessionData.PRMID;
iv.UserID = ReportSessionData.UserID;
iv.UserName = ReportSessionData.UserName;
iv.Data.Open();
iv.SetVariables();
iv.SetMeasures();
iv.InitializeMeasures();
iv.ExecuteMeasures(iv.MeasureList[0]);
DataTable dt = iv.MeasureList[0].OutputTable;
iv.Data.Close();
Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender;
chart1.DataGroupColumn = "Type";
chart1.PlotArea.XAxis.DataLabelsColumn = "PRM";
// chart1.PlotArea.YAxis.AxisLabel.TextBlock.Text = "Count of products by PRM";
chart1.PlotArea.YAxis.AxisLabel.Visible = true;
chart1.Series.Clear();
foreach (DataRow dr in dt.Rows)
{
ChartSeries cs = null;
if (chart1.Series.GetByName(dr["Type"].ToString()) == null)
{
cs = new ChartSeries();
cs.Type = ChartSeriesType.StackedBar;
cs.Name = dr["Type"].ToString();
cs.DataYColumn = "Count";
cs.Appearance.LabelAppearance.Visible = false;
chart1.Series.Add(cs);
}
else
cs = chart1.Series.GetByName(dr["Type"].ToString());
ChartSeriesItem csi = new ChartSeriesItem();
csi.Label.TextBlock.Text = "";
csi.Label.Visible = false;
csi.Label.Appearance.Visible = false;
cs.AddItem(csi);
}
dt.AcceptChanges();
chart.DataSource = dt;
for (int i = 0; i < chart1.Series.Count; i++)
for (int j = 0; j < chart1.Series[i].Items.Count; j++)
{
chart1.Series[i].Items[j].Label.Appearance.Visible = false;
chart1.Series[i].Items[j].Label.Visible = false;
chart1.Series[i].Items[j].Label.TextBlock.Text = "";
chart1.Series[i].Appearance.LabelAppearance.Visible = false;
chart1.Series[i].Appearance.ShowLabels = false;
}
chart1.ChartTitle.TextBlock.Text = "PRM Activity for: " + ReportSessionData.UserName;
Palette palette = new Palette("MyPalette");
palette.Items.Add(new PaletteItem(Color.LightSkyBlue, Color.LightSkyBlue));
palette.Items.Add(new PaletteItem(Color.CadetBlue, Color.CadetBlue));
palette.Items.Add(new PaletteItem(Color.Blue, Color.Blue));
palette.Items.Add(new PaletteItem(Color.LawnGreen, Color.LawnGreen));
palette.Items.Add(new PaletteItem(Color.LightCoral, Color.LightCoral));
palette.Items.Add(new PaletteItem(Color.MediumVioletRed, Color.MediumVioletRed));
palette.Items.Add(new PaletteItem(Color.MistyRose, Color.MistyRose));
palette.Items.Add(new PaletteItem(Color.LimeGreen, Color.LimeGreen));
palette.Items.Add(new PaletteItem(Color.MediumSpringGreen, Color.MediumSpringGreen));
palette.Items.Add(new PaletteItem(Color.Green, Color.Green));
palette.Items.Add(new PaletteItem(Color.DarkGreen, Color.DarkGreen));
palette.Items.Add(new PaletteItem(Color.ForestGreen, Color.ForestGreen));
chart1.CustomPalettes.Add(palette);
chart1.SeriesPalette = "MyPalette";