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";
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.
Jeff,
It is a bit of a pain point in the current version of the API, but there are many valid ways to approach augmenting the tooltip, regardless. If you are just looking to apply some additional formatting to the value in the tooltip, you may want to set a DataPointTemplate for the series, http://help.infragistics.com/NetAdvantage/WPF/2010.2/CLR4.0/?page=xamChart_Using_a_DataTemplate_to_Style_DataPoints.html
This will allow you to specify a value converter when you bind the Tooltip from the DataPointTemplate to the tooltip somewhere on that visual. see: http://community.infragistics.com/forums/p/40864/229969.aspx#229969
You also have other options in terms of augmenting the data being bound to the chart in order to use a simple DataMapping to define the population of the tooltips see the two methods shown below:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataTable testTable = GetTestData(); CreateSeriesLinq(testTable); } private void CreateSeriesExtraColumns(DataTable testTable) { int columnCount = testTable.Columns.Count; for (int i = 0; i < columnCount; i++) { DataColumn newColumn = new DataColumn( testTable.Columns[i].ColumnName + "ToolTip"); testTable.Columns.Add(newColumn); foreach (DataRow row in testTable.Rows) { row[newColumn] = testTable.Columns[i].ColumnName + " = " + row[i]; } } for (int i = 0; i < columnCount; i++) { Series seriesSales = new Series(); seriesSales.ChartType = ChartType.Column; seriesSales.DataSource = testTable; seriesSales.DataMapping = "Value=" + testTable.Columns[i].ColumnName + ";Tooltip=" + testTable.Columns[i + columnCount].ColumnName; seriesSales.Label = testTable.Columns[i].ColumnName; seriesSales.StrokeThickness = .5d; theChart.Series.Add(seriesSales); } } private void CreateSeriesLinq(DataTable testTable) { int columnCount = testTable.Columns.Count; for (int i = 0; i < columnCount; i++) { Series seriesSales = new Series(); seriesSales.ChartType = ChartType.Column; int currIndex = i; seriesSales.DataSource = from row in testTable.AsEnumerable() select new { Value = row[testTable.Columns[currIndex]], Tooltip = testTable.Columns[currIndex].ColumnName + " = " + row[testTable.Columns[currIndex]] }; seriesSales.DataMapping = "Value=Value;Tooltip=Tooltip"; seriesSales.Label = testTable.Columns[i].ColumnName; seriesSales.StrokeThickness = .5d; theChart.Series.Add(seriesSales); } } private DataTable GetTestData() { DataTable testTable = new DataTable("TestTable"); testTable.Columns.Add(new DataColumn("NumberCars")); testTable.Columns.Add(new DataColumn("NumberPlanes")); DataRow row = testTable.NewRow(); row["NumberCars"] = 54; row["NumberPlanes"] = 26; testTable.Rows.Add(row); row = testTable.NewRow(); row["NumberCars"] = 21; row["NumberPlanes"] = 6; testTable.Rows.Add(row); row = testTable.NewRow(); row["NumberCars"] = 12; row["NumberPlanes"] = 31; testTable.Rows.Add(row); row = testTable.NewRow(); row["NumberCars"] = 63; row["NumberPlanes"] = 1; testTable.Rows.Add(row); row = testTable.NewRow(); row["NumberCars"] = 15; row["NumberPlanes"] = 11; testTable.Rows.Add(row); row = testTable.NewRow(); row["NumberCars"] = 3; row["NumberPlanes"] = 52; testTable.Rows.Add(row); row = testTable.NewRow(); row["NumberCars"] = 26; row["NumberPlanes"] = 54; testTable.Rows.Add(row); return testTable; } }
There are other ways of approaching this also. If you have a way you would prefer the API worked, also, please go ahead and make a feature request and hopefully we will be able to accomodate soon. Hope this helps!
Again, I appreciate the idea, but neither of these two methods seem practical for an existing DataTable of information. Are you suggesting that there is no way to assign a DataTemplate or Formatting String to the tooltip for a series when the tooltip values are datamapped to an existing DataTable?
Seems to me like users would need to do this almost every time they build a chart - I can't believe it hasn't bubbled up as a bigger issue before.
I would appreciate conformation of this understanding.
Thanks.
Jeff