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

How to apply color for AdditionalYAxes through coding?

1 Answer 99 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
satish asked on 23 Aug 2010, 09:46 AM
Hi All,

I am using the RadChart for WPF in my project for displaying the Chart as LineSeries, my requirment is like this:
 1) I need to add dataPoints dynamically by reading the output file for each Dataseries
  2) I need to add AdditionalYAxes for each Dataseries
  3) I need to Apply ForeGround color for each DataSeries
   4)And the same DataSeires color i need to apply color for related AdditionalYAxes
I have done upto the Above Three Steps and i am able to add AdditionalYAxes. But i am not able to Apply the color Style for the AdditionYAxes line and also the AdditionalYAxes is not start from X-axes, for now it is starting from X-axes one Step above.

I need to apply the color for AdditionaYAxes for the relating DataSeries and The Line should Start from X-Axes position.

i have attached my codeSnippet below:
.XAML file




UserControl x:Class="TabControl.MainWindow"




















Height="Auto" Width="Auto">















<Style x:Name="CustomAxisLineStyle" TargetType="Line">





<Setter Property="Stroke" Value="Red" />





<Setter Property="StrokeThickness" Value="5" />















<telerikChart:RadChart x:Name="_myChart">

















.Xaml.cs file



private void GenerateSeries(string target, ref DateTime timeStamp, double avgVal, string counterName)





int _minsOffSet=0;




DateTime minDate = DateTime.MaxValue;




DateTime maxDate = DateTime.MinValue;




double minVal = double.MaxValue;




double maxVal = double.MinValue;




DataSeries counterSeries = new DataSeries();


counterSeries.Definition =


new LineSeriesDefinition() { ShowItemLabels = false, ShowItemToolTips = true };


counterSeries.Definition.ItemToolTipFormat =




counterSeries.Definition.AxisName = counterName;



AxisY yAxis = new AxisY();


yAxis.AxisName = counterName;



string legendName = string.Format("{0}", counterName);




ref counterSeries, ref yAxis);




DateTime time = timeStamp.AddMinutes(_minsOffSet);



minVal =


Math.Min(minVal, avgVal);


maxVal =


Math.Max(maxVal, avgVal);




DataPoint dp = new DataPoint(time.ToOADate(), avgVal);


dp.IsDateTime =







if (time > maxDate)


maxDate = time;



if (time < minDate)


minDate = time;



if (avgVal > maxVal)


maxVal = avgVal;



if (avgVal > minVal)


minVal = avgVal;

_myChart.DefaultView.ChartArea.AxisX.MinValue = minDate.ToOADate();

_myChart.DefaultView.ChartArea.AxisX.MaxValue = maxDate.ToOADate();

_myChart.DefaultView.ChartArea.AxisY.MinValue = minVal;

_myChart.DefaultView.ChartArea.AxisY.MaxValue = maxVal;





double graphVariation = maxVal - minVal;




if ((graphVariation > 2) & (graphVariation <= 9))



_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =







else if (graphVariation <= 2)



_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =










_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =




_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =








private void SetLegendDetails(string legendName, ref DataSeries dataSeries, ref AxisY yAxis)



_myChart.DefaultView.ChartLegend.Header =




_myChart.DefaultView.ChartLegend.UseAutoGeneratedItems =




dataSeries.LegendLabel = legendName;

dataSeries.Definition.Appearance.Foreground =


new SolidColorBrush(Colors.Green);




Style customAxisYStyle = this.Resources["CustomAxisYStyle"] as Style;


_myChart.DefaultView.ChartArea.AxisY.AxisStyles.AxisLineStyle = customAxisYStyle;



I have attaching the Chart ScreenShot what i implemented.
Please see in Attachments
i am  calling the GenerateSeries Method every time for loading the X-Axis value and Y-Axes value.
Please any one help me how to apply color and starting position of AdditionaYAxes.
This is very urgent Requirment.

Thanks and Regards

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 26 Aug 2010, 08:14 AM
Hi Satish,

As I understand from your post you need to set different stroke color for every additional y axis. I noticed something wrong in your code - please use the following style for your axes:

<Style x:Key="CustomAxis" TargetType="Line">
      <Setter Property="Stroke" Value="Green" />
      <Setter Property="StrokeThickness" Value="5" />

The difference is that you need to use x:Key instead of x:Name. Having separate style for every y axis should fix your problem.

Regarding your second question (about the start point of the additional y axes), I have tried to reproduce it with the provided code, but unfortunately with no success. A possible hint is that may be it is caused by the data you set.

Could you please provide us with more information? A sample project would be the best option.

Thank you,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question