databinding to ChartArea

2 posts, 0 answers
  1. Lukas
    Lukas avatar
    5 posts
    Member since:
    May 2009

    Posted 22 Oct 2009 Link to this post

    Hi,
    how can I bind data to ChartArea? It doesnt have SeriesMapping property.

    I have a chart that have 3 chart areas. I want to bind the same collection (Observable collection of ViewModels) to these areas, but each area will display different property from ViewModel. Or is making 3 Charts instead of 3 ChartAreas a better approach? (but then i would loose the fancy background).

    Second question.. can I save ChartArea to picture or this is possilbe only for charts?

    Thanks
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 26 Oct 2009 Link to this post

    Hi Lukas,

    Databinding to multiple ChartAreas will be supported with the Q3 2009 release scheduled for November. Currently you can preview the functionality in the public BETA release available for download in your Client.Net account:

    XAML:
    <telerik:RadChart x:Name="RadChart1" UseDefaultLayout="False">
        <telerik:RadChart.SeriesMappings>
            <chart:SeriesMapping>
                <chart:SeriesMapping.ItemMappings>
                                <chart:ItemMapping FieldName="YValue" DataPointMember="YValue" />
                </chart:SeriesMapping.ItemMappings>
            </chart:SeriesMapping>
            <chart:SeriesMapping ChartAreaName="ChartArea1">
                <chart:SeriesMapping.ItemMappings>
                                <chart:ItemMapping FieldName="YValue" DataPointMember="YValue" />
                </chart:SeriesMapping.ItemMappings>
            </chart:SeriesMapping>
            <chart:SeriesMapping ChartAreaName="ChartArea2">
                <chart:SeriesMapping.ItemMappings>
                                <chart:ItemMapping FieldName="YValue" DataPointMember="YValue" />
                </chart:SeriesMapping.ItemMappings>
            </chart:SeriesMapping>
        </telerik:RadChart.SeriesMappings>
        <StackPanel Orientation="Vertical">
            <chart:ChartArea x:Name="ChartArea1" />
            <chart:ChartArea x:Name="ChartArea2" />
        </StackPanel>
    </telerik:RadChart>

    C#
    SeriesMapping sm = new SeriesMapping();
    sm.ChartArea = this.ChartArea1;
    sm.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
    RadChart1.SeriesMappings.Add(sm);
     
    sm = new SeriesMapping();
    sm.ChartArea = this.ChartArea2;
    sm.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
    RadChart1.SeriesMappings.Add(sm);
     
    RadChart1.ItemsSource = new List<ChartData>()
        {
                        new ChartData(1),
                        new ChartData(2),
                        new ChartData(3),
                        new ChartData(4),
                        new ChartData(5),
                        new ChartData(6)
        };
     
    public class ChartData
    {
        public ChartData(double y)
        {
                        this.YValue = y;
        }
     
        public ChartData(DateTime x, double y)
        {
                        this.XValue = x;
                        this.YValue = y;
        }
     
        public DateTime XValue
        {
                        get;
                        set;
        }
     
        public double YValue
        {
                        get;
                        set;
        }
    }


    As for your second question -- export to image is supported only for the chart control and not for the ChartArea.


    All the best,
    Manuel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top