Different labels

11 posts, 0 answers
  1. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 11 May 2013 Link to this post

    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?
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 13 May 2013 Link to this post

    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.
  3. DevCraft banner
  4. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 14 May 2013 Link to this post

    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
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 14 May 2013 Link to this post

    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.
  6. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 14 May 2013 Link to this post

    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.
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 17 May 2013 Link to this post

    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.
  8. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 19 May 2013 Link to this post

    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?
  9. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 22 May 2013 Link to this post

    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.
  10. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 23 May 2013 Link to this post

    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.
  11. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 23 May 2013 Link to this post

    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.
  12. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 27 May 2013 Link to this post

    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.
Back to Top
DevCraft banner