Hi,
I am using ClipTextAxisLabelLayoutBehavior to trim labels and display ellipces for data on X axis . Now i would like to display tooltip on mouse hover to show the entire label. I observed tooltips are only appearing for data on chart but not for labels.
Please suggest.
Thanks
bp
here is some code you can use to achieve this. unfortunately, you are constrained to using <ITEM_LABEL> for all tooltips in this example. if you want to request this as an official feature of winchart then please visit this page: https://es.infragistics.com/community/ideas
using
System;
Infragistics.Win.UltraWinChart;
System.Windows.Forms;
Infragistics.UltraChart.Resources.Appearance;
Infragistics.UltraChart.Shared.Styles;
System.Drawing;
Infragistics.UltraChart.Shared.Events;
Infragistics.UltraChart.Core.Primitives;
System.Collections;
Infragistics.UltraChart.Resources;namespace TooltipXAxisLabels
{
public partial class Form1 : Form
private UltraChart UltraChart1 { get; set; }public Form1()
// add a chart to the formthis.UltraChart1 = new UltraChart();
this.UltraChart1.Dock = DockStyle.Fill;this.Controls.Add(this.UltraChart1);
// bind it to some series data with extra-long item labels.NumericSeries series1 = new NumericSeries();
series1.Points.Add(
new NumericDataPoint(1.0, "Point A AAAAAAAAAAAAAAAAA", false));series1.Points.Add(new NumericDataPoint(2.0, "Point B BBBBBBBBBBBBBBBBB", false));
new NumericDataPoint(3.0, "Point C CCCCCCCCCCCCCCCCC", false));series1.Points.Add(new NumericDataPoint(4.0, "Point D DDDDDDDDDDDDDDDDD", false));
this.UltraChart1.Series.Add(series1);
// configure x axis labelsthis.UltraChart1.Axis.X.Labels.Orientation = TextOrientation.Horizontal;
this.UltraChart1.Axis.X.Labels.SeriesLabels.Visible = false;
// add a text clipping behaviorthis.UltraChart1.Axis.X.Labels.Layout.Behavior = AxisLabelLayoutBehaviors.UseCollection;
ClipTextAxisLabelLayoutBehavior clipper = new ClipTextAxisLabelLayoutBehavior();clipper.ClipText = true;
clipper.Enabled =
true;clipper.EnableRollback = false;
clipper.HideText =
true;clipper.Trimming = StringTrimming.EllipsisCharacter;
this.UltraChart1.Axis.X.Labels.Layout.BehaviorCollection.Add(clipper);
// handle the chartdrawitem eventthis.UltraChart1.ChartDrawItem += new Infragistics.UltraChart.Shared.Events.ChartDrawItemEventHandler(UltraChart1_ChartDrawItem);
// the tooltips must use this format for the sample to work properlythis.UltraChart1.Tooltips.FormatString = "<ITEM_LABEL>";
}
private void UltraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e)
Text textPrim = e.Primitive as Text;
// check if the primitive is a Text primitive.if (textPrim != null)
// this is the code you can use to make any primitive show tooltips.textPrim.Caps = PCaps.HitTest | PCaps.Tooltip;
textPrim.Chart =
this.UltraChart1.ChartType;textPrim.Row = Math.Max(textPrim.Row, 0);textPrim.Column = Math.Max(textPrim.Column, 0);
this does depend on the chart type you are using. if the item labels are on the Y axis, then try setting the tooltips.formatstring to <DATA_VALUE> to display the data value on the tooltip. this would be the x-axis value for charts like BarChart. or if you're using a chart with 2 numeric axes like ScatterChart, try <DATA_VALUE_X> as your formatstring.
I'm using ScatterChart, <DATA_VALUE_X> doesn't change anything.
i'm having trouble understanding your situation based on the few sentences you have posted. could you try describing the whole problem, along with the expected result vs. the actual result? images or sample could would also be a big help.
I tried the hack, but I am always getting row or column of text primitive as -1, because of which i am seeing the same value (or 0 row value) for all the text primitives. Any idea why row or column for the text primitive is always coming as -1, or is there a way to identify the text primitive.
I was binding the chart with the dataTable in my sample.
you can get the text string of the Text Primitive using t.GetTextString() -- is that enough to identify it?