This is a migrated thread and some comments may be shown as answers.
Custom values on Y-Axis
1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
siva sankar
Top achievements
Rank 1
siva sankar asked on 02 Nov 2012, 10:04 AM
Hai,
 
             I want  custom value (like 33,128, 134,138,148,158) on Y-axis of wpf chart, instead of 20,30,40,50,60,70......170.
Iam attaching my chart here.


Thanks

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 07 Nov 2012, 12:40 PM
Hello,

The RadChart does not support such functionality, however you can manually iterate through the labels of the axis and hide all the labels, except the ones which represent a data point present in the chart. Here is an example :
this.RadChart1.DefaultView.ChartArea.AxisY.Step = 1;
RadChart1.LayoutUpdated += this.RadChart1_LayoutUpdated;
 
private void RadChart1_LayoutUpdated(object sender, System.EventArgs e)
{
    HideUnneededLabels();
}
         
void HideUnneededLabels()
{
    UIElement axisY =
        RadChart1.DefaultView.ChartArea.
        ChildrenOfType<VerticalAxisLabels2D>().FirstOrDefault();
 
    var labels = from axisLabel2D in axisY.ChildrenOfType<AxisLabel2D>()
        select axisLabel2D.ChildrenOfType<TextBlock>().FirstOrDefault();
 
    var yValues = GetUniqueYValues();
 
    foreach (var label in labels)
    {
        if (!yValues.Contains(double.Parse(label.Text)))
            label.Visibility = System.Windows.Visibility.Collapsed;
    }
}
 
private HashSet<double> GetUniqueYValues()
{
    var result = new HashSet<double>();
 
    foreach (var series in this.RadChart1.DefaultView.ChartArea.DataSeries)
    {
        foreach (var dataPoint in series)
        {
            result.Add(dataPoint.YValue);
        }
    }
 
    return result;
}

Don't forget to set the "resolution" of the axis by changing the AxisY.Step property to 1 (for example), because otherwise at 137, there won't be a label to hide. I have attached an image of the result that I get.

Kind regards,
Petar Kirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Chart
Asked by
siva sankar
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or