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

ItemToolTipFormat issue

2 Answers 129 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Igor T
Top achievements
Rank 1
Igor T asked on 17 Nov 2010, 01:41 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Evgenia
Telerik team
answered on 19 Nov 2010, 11:06 AM
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
0
Igor T
Top achievements
Rank 1
answered on 19 Nov 2010, 02:07 PM
Thanks! That solved it.
Tags
Chart
Asked by
Igor T
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Igor T
Top achievements
Rank 1
Share this question
or