I have a seemingly simple requirement. I want a tooltip to popup when the user hovers over a charted datapoint (2d column chart).
All the examples I've found (including feature brower) show tooltips set at the (hard coded) datapoint object. However, I'm adding the series to the chart in code behind by mapping to columns in DataTable and setting tooltips for the individual datapoints doesn't work.
How do I bind tooltips to the column value? I would think this is a no brainer... but I'm stumped!
Thanks in advance for the help.
You should be able to specify the tooltip mapping in the DataMapping string. See if this works for you:<igChart:XamChart x:Name="chart"> <igChart:XamChart.Series> <igChart:Series ChartType="Column"/> </igChart:XamChart.Series></igChart:XamChart>
DataTable dt = new DataTable();dt.Columns.Add("label", typeof (string));dt.Columns.Add("value", typeof (double));dt.Rows.Add(new object[] {"item1", 3});dt.Rows.Add(new object[] {"item2", 7});dt.Rows.Add(new object[] {"item3", 2});dt.Rows.Add(new object[] {"item4", 8});
Series series = chart.Series[0];series.DataSource = dt;series.DataMapping = "Label=label;Value=value;Tooltip=value";
So far, so good. Indeed, that does get me 1 step closer. My decimal data values now shows up as a tooltip.
Now I need to format my decimal values as currency. I'm trying to follow some forum data template examples, but am having difficulty because I'm charting multiple series (data columns) so the column names are different for each column.
I'm loading the series with the following code:
for (int i = 1; i < dt.Columns.Count - 1; i++) { seriesTaxBrackets = new Series(); seriesTaxBrackets.ChartType = ChartType.Column; seriesTaxBrackets.DataSource = dt; seriesTaxBrackets.DataMapping = "Value=" + dt.Columns[i].ColumnName + ";Tooltip=" + dt.Columns[i].ColumnName; seriesTaxBrackets.Label = (string)FindResource("Bracket") + " " + i.ToString(); seriesTaxBrackets.StrokeThickness = .5d; chartTaxBrackets.Series.Add(seriesTaxBrackets);}
Do you know where I can squeeze in a String.Format command that will get applied to the rendered tooltip?
Thanks again.
Max & Co:
I've continued to explore solutions to formatting the result of the databound value for a tooltip - with no success.
I was hopeful that I could create a tooltip with a properly formatted ContentStringFormat set and then add it to the series before adding the series to the chart - no joy. It appears that the DataMapping process overrides the series tooltip somehow. (If I remove tooltip from the datamapping string, my customized tooltip is used, but without any associated value). I even thought about creating a ValueConverter, but don't see that the DataMapping property supports it.
I could really use some direction here - Thanks!
Doing something like this can give you more control over what gets displayed in the tooltip and how: http://forums.infragistics.com/forums/p/38424/221145.aspx#221145
If you do that then you should be able to throw in some value converters into the tooltip template, etc. Let me know if you need additional direction for this appoach. Hope this helps!
-Graham
Another way of approaching it would be to create a property on your data items that preformats the value as a currency in string format for use as the backing property for the Tooltip.