This is a migrated thread and some comments may be shown as answers.

Styling a Chart programmatically is a nightmare

5 Answers 266 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gordon
Top achievements
Rank 1
Gordon asked on 16 Nov 2011, 02:12 AM
I'm having quite a few problems styling a Telerik.Reporting.Chart object. The object itself was created using the designer, but the actual information for the chart, such as title, series, etc is filled in at runtime programmatically.

First of all, I was attempting to set the colors for different series in the following manner:
salesSeries.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Gradient;
salesSeries.Appearance.FillStyle.MainColor = Color.White;
salesSeries.Appearance.FillStyle.SecondColor = Color.Black;

But the colors are overridden by the style placed on the chart in the designer. However, if the FillType is set to Solid, I have no problems setting the color.

Second of all, I found this little oddity when trying to set the background color of the entire chart. When setting the background fill as so:
resultChart.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
resultChart.Appearance.FillStyle.MainColor = Color.White;

It ended up using the default background from the skin. However, if I change "Color.White" to "Color.FromArgb(255,255,255)" (still white) it works properly.

Finally, how do you change the font size for the axis labels? My X-axis labels are a little too wide for the text that's in them and I need to shrink the font a little, but I couldn't find any way to do so.

5 Answers, 1 is accepted

Sort by
0
IvanDT
Telerik team
answered on 18 Nov 2011, 06:02 PM
Hello Gordon,

You should take in consideration the following when you set custom properties in Chart Report Item:

  • Chart's Skin - This is with high priority for Chart style(Chart&Series font, Chart&Series borders and etc.);
  • Series Palette - This is second priority after Skin for Series Style(Series font, Series borders and etc.). If Chart's Skin is set it will overwrite Series Palette customizations;
  • Series(Collection) Appearance - This is with third priority after Series Palette. Here for every chart series you can set font, border and etc. If some of the above properties are applied they will overwrite Series Appearance.
  • Custom Palettes - This with forth priority after Series(Collection) Appearance. If some of the above properties are applied they will overwrite the Custom Palettes

The oddities, observed by you, will be taken in consideration for the development of the Chart Report Item. About the font size of the labels in the XAxis, you can find it here:
Chart -> PlotArea -> XAxis -> AxisLabel -> TextBlock -> Appearance -> TextProperties -> Font -> Size

Regards,
IvanDT
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Gordon
Top achievements
Rank 1
answered on 28 Nov 2011, 05:35 AM
So it doesn't matter what properties I set where, the gradient colors will always be taken from the chart's skin?
We ended up finding a skin with colors close to what we wanted for the series, and customized the other colors in code, which works well enough for our purposes for now.

The Size attribute of the font mentioned is read-only and cannot be changed. I tried the following code:
//resultChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Font.Size = 8; //Size is Read Only
resultChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Font =
    new System.Drawing.Font(
        resultChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Font.FontFamily,
        8
    );
But that didn't appear to affect anything, either. Any suggestions?
0
Steve
Telerik team
answered on 29 Nov 2011, 04:14 PM
Hello Gordon,

The correct property path is:

resultChart.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font.Size

Please excuse us for the misunderstanding.

Regards,
Steve
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Nirav
Top achievements
Rank 1
answered on 02 Sep 2013, 12:03 PM
Hello,

I have used the path specified as "chart.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font.Size" but its Read Only property so i am not able to set the font size, can you please tell me the exact property where we can set font family and size ?
0
Nasko
Telerik team
answered on 04 Sep 2013, 01:16 PM
Hello Nirav,

In order to set the font family, size and style you can try the following :

chart.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font = new System.Drawing.Font("Verdana", 10.2F, FontStyle.Bold);

Regards,
Nasko
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Gordon
Top achievements
Rank 1
Answers by
IvanDT
Telerik team
Gordon
Top achievements
Rank 1
Steve
Telerik team
Nirav
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or