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

Custom Label

8 Answers 120 Views
Chart
This is a migrated thread and some comments may be shown as answers.
shivinder
Top achievements
Rank 1
shivinder asked on 15 Feb 2011, 08:16 PM
Hi,

i am binding my data  but i want to have my own custom label for data. in addition i dont want to show the label for every data point but for every say 5th point.
how can i achieve this. ???

8 Answers, 1 is accepted

Sort by
0
Missing User
answered on 18 Feb 2011, 06:35 PM
Hello shivinder,

If you want to change the visibility of PointMarks and Labels for Specific points only you can try the following:
var dataSeries = radChart.DefaultView.ChartArea.DataSeries.FirstOrDefault();
if (dataSeries != null)
{
    int i = 1;
    foreach (var point in dataSeries.ToList())
    {
        if (i % 5 != 0)
        {
            point.Label = " ";
        }
        i++;
    }
}

You can find more information about points and labels visibility here.

If you want to change the labels on the AxisX you can do that on LayoutUpdate:
public MainWindow()
{
    InitializeComponent();
    ...
    radChart.LayoutUpdated += new EventHandler(RadChart1_LayoutUpdated);
}
 
void RadChart1_LayoutUpdated(object sender, EventArgs e)
{
    radChart.DefaultView.ChartArea.AxisX.TickPoints[0].Label = " ";
}

I hope this will help you out.

All the best,
Polina
the Telerik team
0
shivinder
Top achievements
Rank 1
answered on 21 Feb 2011, 11:31 PM
Is it possible to bind my labels
0
shivinder
Top achievements
Rank 1
answered on 21 Feb 2011, 11:45 PM
sorry thhis didnt help

i am binding my data through chart.Itemsource but the line
var AllPoints = chart.DefaultView.ChartArea.DataSeries.FirstOrDefault();

gives me null;
0
Missing User
answered on 24 Feb 2011, 03:56 PM
Hi shivinder,

For Label Binding you can use RadChart.SeriesMappings to indicate which property is for the labels. For example you have Custom Data Object with three properties and you map them to the RadChart:
<telerik:RadChart.SeriesMappings>
    <telerik:SeriesMapping>
        <telerik:SeriesMapping.SeriesDefinition>
            <telerik:BarSeriesDefinition ShowItemToolTips="True"/>
        </telerik:SeriesMapping.SeriesDefinition>
        <telerik:SeriesMapping.ItemMappings>
            <telerik:ItemMapping FieldName="Population" DataPointMember="YValue" />
            <telerik:ItemMapping FieldName="Country" DataPointMember="XCategory" />
            <telerik:ItemMapping FieldName="CustomLabel" DataPointMember="Label" />
        </telerik:SeriesMapping.ItemMappings>
    </telerik:SeriesMapping>
</telerik:RadChart.SeriesMappings>

More information can be found here.

In the case when you want to display only Labels for Specific points, you can use the solution proposed in the previous answer. About the exception, you need to get the DataSeries after the chart is already bound to the source. It follows that, this code needs to be placed in an event in which we know that the chart was already bound. For example on RadChart.DataBound event:
void RadChart1_DataBound(object sender, ChartDataBoundEventArgs e)
{
    var dataSeries = radChart.DefaultView.ChartArea.DataSeries.FirstOrDefault();
    if (dataSeries != null)
    {
        int i = 1;
        foreach (var point in dataSeries.ToList())
        {
            if (i % 5 != 0)
            {
                point.Label = " ";
            }
            i++;
        }
    }  
}

I hope this helps.

Kind regards,
Polina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
shivinder
Top achievements
Rank 1
answered on 03 Mar 2011, 09:59 PM
this is my code
chart.ItemsSource = Data;
    SeriesMapping seriesmapping = new SeriesMapping();
            seriesmapping.SeriesDefinition = new LineSeriesDefinition();
            seriesmapping.CollectionIndex =0;

              ItemMapping itemMapping = new ItemMapping();
            itemMapping.DataPointMember = DataPointMember.YValue;
            itemMapping.FieldName = "YValue";
           seriesmapping.ItemMappings.Add(itemMapping);
            ItemMapping itemMapping1 = new ItemMapping();
            itemMapping1.DataPointMember = DataPointMember.XCategory;
            itemMapping1.FieldName = "AxisLabel";
            seriesmapping.ItemMappings.Add(itemMapping1);
            var AllPoints = chart.DefaultView.ChartArea.DataSeries.FirstOrDefault();

then i go on to attempt to get the fifth label to show but here my ALLPoints is null.
0
Missing User
answered on 08 Mar 2011, 09:34 AM
Hi shivinder,

One possible reason for this issue is because you are trying to get the DataSeries when the chart is still not bound. I modified the provided code and attached a sample how to get the DataSeries and to bind custom labels.

I hope this helps.

Kind regards,
Polina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
shivinder
Top achievements
Rank 1
answered on 23 Mar 2011, 09:56 PM
You are totally misunderstanding me.

I DO NOT WANT TO SHOW EVERY FIFTH POINT LABEL. I WANT TO SHOW EVERY 5TH AXIS LABEL.

0
Missing User
answered on 29 Mar 2011, 12:57 PM
Hello shivinder,

Sorry for the misunderstanding.
In order to show every 5th AxisX label you need to re-template the ItemLabelStyle and bind the desired strings by a custom converter. To indicate the TickPoints' labels that will be modified, you will need to set a custom word to the RadChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat and use it to find the needed TickPoints.
In the attached file you can find an example how to use the converter and Category axis, so that the data is treated as a sequence of non-numerical text labels.

Let me know how this approach meets your requirements, or you find that I am leaving something out.

All the best,
Polina
the Telerik team
Tags
Chart
Asked by
shivinder
Top achievements
Rank 1
Answers by
Missing User
shivinder
Top achievements
Rank 1
Share this question
or