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

Dynamically Change Y-Axis Title Style for RadCartesianChart

2 Answers 199 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Denin
Top achievements
Rank 1
Veteran
Denin asked on 09 Jun 2020, 04:35 PM

Hello,     

 

I'm using the RadCartesianChart to display a dynamic number of series using two y-axis. I'd like to set the style of the vertical axis title. Any help would be appreciated. 

When I have one y-axis, I can do this:

<telerik:RadCartesianChart.VerticalAxis>
   <telerik:LinearAxis Minimum="0" x:Name="verticalAxis"                                     
                         HorizontalLocation="Left"
                         MajorTickStyle="{StaticResource tickStyle}"
                         LineThickness="1.5"
                         LineStroke="Gray"
                         LabelStyle="{StaticResource axisLabelStyle}" >
      <telerik:LinearAxis.Title>
         <TextBlock FontWeight="Bold" FontSize="13" x:Name="txtYAxisTitle"/>
      </telerik:LinearAxis.Title>
   </telerik:LinearAxis>
</telerik:RadCartesianChart.VerticalAxis>

 

But Since I can only create one y-axis this way, I can't do it this way. Instead, I have created two y-axis dynamically. When I do that, I don't know how to set the style of the title (ie. txtYAxisTitle from above). This is what I have that isn't working:

LinearAxis verticalAxisOne = new LinearAxis();
verticalAxisOne.Style = Resources["AxisTitleStyle"] as Style;

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 12 Jun 2020, 04:35 PM

Hello Tyson,

To achieve your requirement, you can set the Title property also in code. For example:

private TextBlock axisOneTitle;

private void PrepareAxis()
{
	this.axisOneTitle = new TextBlock();
	LinearAxis verticalAxisOne = new LinearAxis() { Title = this.axisOneTitle };
	verticalAxisOne.Style = Resources["AxisTitleStyle"] as Style;
}

private static void UpdateAxisTitle(TextBlock titleVisual, string newTitle)
{
	titleVisual.Text = newTitle;
}

Regards,
Martin Ivanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Denin
Top achievements
Rank 1
Veteran
answered on 15 Jun 2020, 04:39 PM

Thank you for the reply. This didn't work exactly as described. Instead of setting the style of verticalAxisOne, I set the style of the TextBlock itself. Also note that Resources["AxisTitleStyle"] didn't work for finding the resource, I had to use Application.Current. Thanks for pointing me in the right direction.

 

 

this.axisOneTitle.Style = Application.Current.Resources["axisLabelStyle"] as Style;
Tags
Chart
Asked by
Denin
Top achievements
Rank 1
Veteran
Answers by
Martin Ivanov
Telerik team
Denin
Top achievements
Rank 1
Veteran
Share this question
or