ItemToolTipFormat issue

3 posts, 1 answers
  1. Igor T
    Igor T avatar
    8 posts
    Member since:
    Mar 2010

    Posted 17 Nov 2010 Link to this post

    Hi,
    I can't get the tooltip to display formatted date field (it just gives me the formatting expression back) please see code snippet below in bold. However if I remove "ChartAggregateFunction.Sum" below it displays fine. Can you please tell me the correct way to access that? 

    I was following the example for charts and everything works, except the tooltip - Creation part. I've attached an image of demo example.


    Here's the snippet, my source is a List<MyChartItem>, where MyChartItem contains two properties: int Interest, DateTime Creation.

    SeriesMapping seriesMapping = new SeriesMapping();
                seriesMapping.SeriesDefinition = new BarSeriesDefinition();
                seriesMapping.SeriesDefinition.ShowItemLabels = false;
                seriesMapping.SeriesDefinition.ShowItemToolTips = true;
                seriesMapping.SeriesDefinition.ItemToolTipFormat = string.Concat("Month: ", "#DATAITEM.Creation{MMM-yy}", "\r\nInterest: #Y");

     

                seriesMapping.GroupingSettings.GroupDescriptors.Add(new ChartYearGroupDescriptor());
                seriesMapping.GroupingSettings.GroupDescriptors.Add(new ChartMonthGroupDescriptor());
                seriesMapping.ItemMappings.Add(new ItemMapping("Interest", DataPointMember.YValue, ChartAggregateFunction.Sum));
                seriesMapping.ItemMappings.Add(new ItemMapping("Creation", DataPointMember.XCategory));
                MyChart.SeriesMappings.Add(seriesMapping);
                MyChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "MMM-yy";
               

                this.MyChart.ItemsSource = chartItems;

  2. Answer
    Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 19 Nov 2010 Link to this post

    Hi Igor,

    The reason for this behavior is in the ChartYearGroupDescriptor and ChartMonthGroupDescriptor used. When grouping items each bar no longer represents a single data item (i.e. an object from the underlying data). In this case you may have an object for every day or even for every hour, but RadChart will display a single bar for the entire month, showing the sum of all items. When grouping, the DataItem is actually a generic list of KeyValue pairs, where each pair's key is the GroupDescriptor's member and the value is the actual value for the group. Knowing that you have added ChartYearGroupDescriptor and ChartMonthGroupDescriptor you can attach to the ItemDatabound event and compose the tooltip:

    void MyChart_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
           {
               List<KeyValuePair<string, string>> dataItem = e.DataItem as List<KeyValuePair<string, string>>;
               DateTime date = new DateTime(int.Parse(dataItem[0].Value), int.Parse(dataItem[1].Value), 1);
               e.DataPoint.Tooltip = string.Format("Month: {0:MMM-yy} \n Interest: {1}", date, e.DataPoint.YValue);
           }

    You can find a small example attached.

    All the best,
    Evgenia
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. Igor T
    Igor T avatar
    8 posts
    Member since:
    Mar 2010

    Posted 19 Nov 2010 Link to this post

    Thanks! That solved it.
Back to Top