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

Different labels

10 Answers 73 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Darin
Top achievements
Rank 1
Darin asked on 11 May 2013, 05:47 AM
I'm trying to bind a bar chart or pie chart to a view model.  The view model contains the following properties:

#region Properties
       public double Value
       {
            get { return _value; }
            set { _value = value; }
       }
       
       public string Name
       {
           get { return _name; }
           set { _name = value; }
       }
#endregion Properties

How would I go about using the property 'Name' for the label and 'Value' for the point.  I've tried using PointTemplates and LabelTemplates with no luck.  I'd like to be able to specify a label and value for a pie, line, and bar chart.  Any help?

10 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 13 May 2013, 08:27 AM
Hi Darin,

Thanks for writing.
Please use the LabelDeifinitions property. It also allows you to define a label template. The data context of your label template is a PieDataPoint. This point has a DataItem property which contains a reference to your view model. Here is a simple example:

<chart:RadPieChart x:Name="chart" Palette="Warm">
    <chart:PieSeries ValueBinding="Value">
        <chart:PieSeries.LabelDefinitions>
            <chart:ChartSeriesLabelDefinition>
                <chart:ChartSeriesLabelDefinition.Template>
                    <DataTemplate>
                        <TextBlock Text="{Binding DataItem.Name}"/>
                    </DataTemplate>
                </chart:ChartSeriesLabelDefinition.Template>
            </chart:ChartSeriesLabelDefinition>
        </chart:PieSeries.LabelDefinitions>
    </chart:PieSeries>
</chart:RadPieChart>

this.chart.Series[0].ItemsSource = new ViewModel[]
{
    new ViewModel() { Value = 5, Name = "Item 1" },
    new ViewModel() { Value = 10, Name = "Item 2" },
    new ViewModel() { Value = 15, Name = "Item 3" },
};

Please write again if you need further assistance.

Regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Darin
Top achievements
Rank 1
answered on 14 May 2013, 06:07 AM
Thanks for all of you help!  

Two final questions:

First, is there a simple property that I can set so that the labels rotate for a bar categories?  So instead of them display out horizontally they display vertically?

Second, do you have a simple example of date and time and categorical for a line chart?

Thanks,
Darin
0
Victor
Telerik team
answered on 14 May 2013, 07:20 AM
Hi, Darin

You horizontal axis has a LabelRotationMode property. You can set it to multi line or rotate, this should do the trick.

Can you please explain in more detail about the line chart example? What is your exact requirement?

Kind regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Darin
Top achievements
Rank 1
answered on 14 May 2013, 01:02 PM
For the line chart I'm looking at displaying quantities for given days of the month.  I was going to allow the user to specify a date range and build the line chart off that date range.  I would like to display this quantity per day.

So these changes are for a workout app that I'm working on.  Another thing I'd like to display is the weight change per time you complete a workout or the time change per time you complete a workout.
0
Victor
Telerik team
answered on 17 May 2013, 01:22 PM
Hello Darin,

Please have a look at the attached archive. It demonstrates a simple chart that displays values for certain days.
Basically there are two axes that you can use and these are DateTimeCategoricalAxis and DateTimeContinuousAxis. You can read more about them here. Also, feel free to check out the source code of our Examples app, it is included with the RadControls installation.
If you have more questions feel free to write again.

Kind regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Darin
Top achievements
Rank 1
answered on 19 May 2013, 08:46 PM
Thanks for the example.  Worked great!  What if I wanted to use a TimeSpan as the value instead of a double?   I believe I would just use a ValueConverter I think?  Is that right?
0
Darin
Top achievements
Rank 1
answered on 22 May 2013, 08:15 PM
Any idea how to do this?

I want to be able to display progress on a workouts time.  For example, I have the workout 800m run.  The first time I got on it was 6:20.  The second was 4:30.  I want to be able to show this improvement on the line chart.  However, the Y-axis takes in a double and not a TimeSpan.
0
Victor
Telerik team
answered on 23 May 2013, 11:45 AM
Hello Darin,

Thanks for writing.
Since the vertical axis cannot be another categorical axis it must be a linear axis. As you mention a linear axis cannot display a date time value. This means that you simply have to convert your DateTime value to a double. It can be ticks, seconds, minutes or whatever you find convenient. You can then convert back to a date time with a simple value converter in order to have proper labels.

Regards,
Victor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Darin
Top achievements
Rank 1
answered on 24 May 2013, 04:53 AM
I'm hitting a brick wall.  I have a value converter but I'm curious to what I bind it to.  Do I bind it to the a "value" property on the MajorTickTemplate?  Or LabelTemplate?  I guess that would be my question.  What do I bind the value converter to and how do I do it?  If you have an example of that that would be great.
0
Victor
Telerik team
answered on 27 May 2013, 11:10 AM
Hello Darin,

I have answered your question in the other threads you posted.

Regards,
Victor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart
Asked by
Darin
Top achievements
Rank 1
Answers by
Victor
Telerik team
Darin
Top achievements
Rank 1
Share this question
or