Hi,
On a UltraDataChart I have the ShowDefaultToolTip set to True.
My chart is bound to a IEnumerable and I set the ValueMemberPath for the series to a field called "SummaryColumn1" or "SummaryColumn2".
See below. [items is an IEnumerable object and sumaryColumnName is the name of the property]
ColumnSeries series1 = new ColumnSeries
{ DataSource = items, ValueMemberPath = summaryColumnName, XAxis = xAxis, YAxis = yAxis, IsHighlightingEnabled = true, IsTransitionInEnabled = false, ShowDefaultTooltip = true,};
The Tooltip displays fine. However the Tooltip display the property name as "SummaryColumn1". I need to show a custom text like "Total Price" or something - how do I do that?
Regards,
Naresh Nichani
Hi Naresh,
Currently it is not built into the DataChart to easily modify the DefaultTooltips. You do have the ability through the TooltipContentUpdating event to create your own custom tooltips. How that event works is it gives you the DataContext of the Tooltip, and the CurrentContent control that it is currently showing. Below is a snippet of a simple CustomTooltip:
Control series_TooltipContentUpdating(object sender, ChartTooltipContentEventArgs e) { Panel panel = e.CurrentContent as Panel;
// NOTE: The below check stops the redundant painting of the same tooltip if (panel == null || (panel != null && !panel.Tag.Equals(e.DataContext.Item))) { panel = new Panel(); panel.Tag = e.DataContext.Item; // Needed for the above check to work panel.Size = new Size(300, 80); Color colorItem = e.DataContext.ActualItemBrush.Color.ToColor(); Label l1 = new Label() { Text = e.DataContext.Series.GetType().FullName, Width = 290 }; l1.Location = new System.Drawing.Point(5, 5); Label l2 = new Label() { Text = e.DataContext.Series.Name, Width = 290 }; l2.Location = new System.Drawing.Point(5, 28); Label l3 = new Label() { Text = e.DataContext.Item.ToString(), Width = 290 }; l3.Location = new System.Drawing.Point(5, 51);
l2.ForeColor = colorItem; l3.ForeColor = colorItem; panel.Controls.AddRange(new Control[] { l1, l2, l3 }); } return panel; }
If you like the style of the DefaultTooltip, this event will fire with the DefaultTooltips enabled. While there is not a built in easy way to update the DefaultTooltip, you can access the control via the e.CurrentContent, and from there search through the UserControl's control structure to find the Label text and update it. Let me know if this helps?
Hello Mike,
Do you have this code in .Net VB?
Thanks,
Tuoc.
Thanks.
First can let me know or point me to an article on the differences between UltraChart and UltraDataChart. Which is the better one to use?
I tried the following code -
Control series1_TooltipContentUpdating(object sender, ChartTooltipContentEventArgs e) {
Control ctl = e.CurrentContent;
if (ctl != null && e.DataContext.Item != null) { ctl.SuspendLayout(); SetControlText(ctl, e.DataContext.Item); ctl.ResumeLayout(); } return ctl;
}
private void SetControlText(Control ctl, object item) { foreach (Control ctl1 in ctl.Controls) { Control ctl2 = ctl1; if (ctl2.Text.Equals(string.Format("{0}:",_yFieldName))) { ctl2.Text = ctl2.Text.Replace(_yFieldName, _yFieldDisplayName); } SetControlText(ctl2, item); } }
This seems to find the text and replace it. However the label displayed is blurry on the screen.
Naresh
D-Tools Inc.