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

Change the Y-AXIS ItemLabel styles at runtime

2 Answers 93 Views
Chart
This is a migrated thread and some comments may be shown as answers.
vijay
Top achievements
Rank 1
vijay asked on 27 Jul 2011, 07:34 AM

Hi All,

I am Working with horizontal bar series and I am binding few measures and total to the chart

Meausres as well as Total showing in one graph(Please see the attachment)

For example  Y-axis itemlabels are

Measure1: 10

Measure2: 10

Measure 3:10

Total          : 30

Now my requirement is I have to make the difference for styles of measures and total

So I have to apply the different style to “Total” Item label at runtime.(Like making the total as bold somethig)

I tried but not able to succeed.

Can you people please help me to get the solution for this.

as for the graph here i am using 4 horizontal stack bar series 
series1 is 0 to 25 
series2 is 25 to 50 
series3 is 50 to 75 
series4 is 75 to 100 

and i am binding the chart directly to the list. 

Please verify the attached graph for more clarification.

Thanks in advance
-VIjay Kommalapati

2 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 29 Jul 2011, 12:59 PM
Hi Vijay,

Here is a possible solution for your scenario:

1. Set a custom style where for example you have a setter with red foreground:
<UserControl.Resources>
    <Style x:Key="CustomLabel" TargetType="TextBlock">
        <Setter Property="Foreground" Value="Red" />
        <Setter Property="TextAlignment" Value="Right" />
    </Style>
</UserControl.Resources>

2. On the ChartArea Loaded event you can set this custom style to the first label:
private void ChartArea_Loaded(object sender, EventArgs e)
{
    ChartArea area = sender as ChartArea;
 
    VerticalAxisLabels2D axisLabelsContainer = area.FindChildByType<VerticalAxisLabels2D>();
    IList<AxisLabel2D> axisLabels = axisLabelsContainer.ChildrenOfType<AxisLabel2D>();
    Style style = this.Resources["CustomLabel"] as Style;
 
    axisLabels.FirstOrDefault<AxisLabel2D>().ItemLabelStyle = style; 
}

Please try the approach above and let us know whether this helps you.

Regards,
Sia
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
vijay
Top achievements
Rank 1
answered on 10 Aug 2011, 08:45 AM
It's working perfectly.

Thanks a Lot.
Tags
Chart
Asked by
vijay
Top achievements
Rank 1
Answers by
Sia
Telerik team
vijay
Top achievements
Rank 1
Share this question
or