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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerikChart="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:telerikCharting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"
Height="Auto" Width="Auto">
<Grid>
<Grid.Resources>
<Style x:Name="CustomAxisLineStyle" TargetType="Line">
<Setter Property="Stroke" Value="Red" />
<Setter Property="StrokeThickness" Value="5" />
</Style>
</Grid.Resources>
<telerikChart:RadChart x:Name="_myChart">
</telerikChart:RadChart>
</Grid>
</
UserControl>
.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 =
"#SERIESLABEL\n#Y";
counterSeries.Definition.AxisName = counterName;
AxisY yAxis = new AxisY();
yAxis.AxisName = counterName;
string legendName = string.Format("{0}", counterName);
SetLegendDetails(legendName,
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 =
true;
counterSeries.Add(dp);
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;
_myChart.DefaultView.ChartArea.DataSeries.Add(counterSeries);
_myChart.DefaultView.ChartArea.AdditionalYAxes.Add(yAxis);
double graphVariation = maxVal - minVal;
if ((graphVariation > 2) & (graphVariation <= 9))
{
_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =
"n1";
}
else if (graphVariation <= 2)
{
_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =
"n3";
}
else
{
_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =
"n0";
_myChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat =
"0";
}
}
private void SetLegendDetails(string legendName, ref DataSeries dataSeries, ref AxisY yAxis)
{
_myChart.DefaultView.ChartLegend.Header =
"";
_myChart.DefaultView.ChartLegend.UseAutoGeneratedItems =
true;
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
Satish