Hai
In ultra chart How can I show Tooltip for X,Y Axis Labels? The values need to be shown on mouse over. How can I do this?
Thanks
Sridhar
question is answered here: http://community.infragistics.com/forums/p/4740/28139.aspx and here: http://community.infragistics.com/forums/p/24452/90134.aspx
I tried and could not get success for showing values in tooltip on axis. I am using asp.net web application. Can you just tell steps to do? I could not get result by your win application code forums. Remember I just want to show $0, $2000000 etc in tooltip. Please refer the attachment.
today i looked at this more closely and remembered that it's a bit more complicated on the web; you have to add a transparent Box primitive to show the tooltip, implement IRenderLabel, and manipulate a few other things to get it working. but here you go...
protected void Page_Load(object sender, EventArgs e) { this.UltraChart1.Data.DataSource = Infragistics.UltraChart.Data.DemoTable.Table(); this.UltraChart1.Data.DataBind(); this.UltraChart1.FillSceneGraph += new Infragistics.UltraChart.Shared.Events.FillSceneGraphEventHandler(UltraChart1_FillSceneGraph); Hashtable labelRenderers = new Hashtable(); labelRenderers.Add("MY_LABEL", new MyLabelRenderer()); this.UltraChart1.LabelHash = labelRenderers; this.UltraChart1.Tooltips.FormatString = "<MY_LABEL>"; } internal class MyLabelRenderer : IRenderLabel { public string ToString(Hashtable context) { int row = Convert.ToInt32(context["DATA_ROW"]); if (row > 999) { return context["MY_VALUE"].ToString(); } else { return context["DATA_VALUE"].ToString(); } } } void UltraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { Axis yAxis = e.Grid["Y"] as Axis; if (yAxis == null) { return; } PrimitiveCollection primitivesToAdd = new PrimitiveCollection(); int pointCounter = 0; foreach (Primitive p in e.SceneGraph) { Text t = p as Text; if (t != null && t.bounds.Right < yAxis.startPoint.X) { Box boxToAdd = new Box(t.bounds); boxToAdd.PE.FillOpacity = boxToAdd.PE.StrokeOpacity = 0; boxToAdd.Caps = PCaps.Tooltip | PCaps.HitTest; boxToAdd.Layer = e.ChartCore.GetChartLayer(); boxToAdd.Chart = e.ChartCore.ChartType; boxToAdd.Row = boxToAdd.Column = 1000 + pointCounter++; boxToAdd.Value = double.Parse(t.GetTextString()); boxToAdd.Tags = new Hashtable(); boxToAdd.Tags.Add("MY_VALUE", boxToAdd.Value); primitivesToAdd.Add(boxToAdd); } } e.SceneGraph.AddRange(primitivesToAdd.ToArray()); }
Thanks It works fine for Y axis, i need that logic for X axis also and the columns should have
FormatString
="<ITEM_LABEL> (<DATA_VALUE:>)"
Because I have to show combined tooltips for column values.
Sridhar said:Thanks It works fine for Y axis, i need that logic for X axis
in the FillSceneGraph method, add
Axis xAxis = e.Grid["X"] as Axis;
and change the condition
if (t != null && t.bounds.Right < yAxis.startPoint.X)
to
if (t != null && (t.bounds.Right < yAxis.startPoint.X || t.bounds.Top > xAxis.startPoint.Y))
Sridhar said: also and the columns should have FormatString ="<ITEM_LABEL> (<DATA_VALUE:>)"
also and the columns should have
change
return context["DATA_VALUE"].ToString();
return context["ITEM_LABEL"].ToString() + " (" + context["DATA_VALUE"].ToString() +")";
I tried this as given below. I could not get tooltip over X axis since it is a name(String) I think it wil l work for integers. Can you guide me. I attached the column chart screenshot.
protected void Chart_FillSceneGraph(object sender, FillSceneGraphEventArgs
e)
{
Axis yAxis = e.Grid["Y"] as Axis
;
Axis xAxis = e.Grid["X"] as Axis
if (yAxis == null
)
return
}
PrimitiveCollection primitivesToAdd = new PrimitiveCollection
();
int
pointCounter = 0;
foreach (Primitive p in
e.SceneGraph)
Line l = p as Line
if (l != null
&& l.p1.Y == l.p2.Y)
// this should be the x axis line
l.p1.X = yAxis.startPoint.X;
l.p2.X = e.ChartCore.GetChartLayer().GetOuterBounds().Right;
if (t != null
&& (t.bounds.Right < yAxis.startPoint.X || t.bounds.Top > xAxis.startPoint.Y))
Box boxToAdd = new Box
(t.bounds);
boxToAdd.PE.FillOpacity = boxToAdd.PE.StrokeOpacity = 0;
boxToAdd.Caps =
PCaps.Tooltip | PCaps
.HitTest;
boxToAdd.Layer = e.ChartCore.GetChartLayer();
boxToAdd.Chart = e.ChartCore.ChartType;
boxToAdd.Row = boxToAdd.Column = 1000 + pointCounter++;
double
k;
if (double.TryParse(t.GetTextString(), out k) == true
boxToAdd.Value =
.Parse(t.GetTextString());
boxToAdd.Tags =
new Hashtable
boxToAdd.Tags.Add(
"MY_VALUE"
, boxToAdd.Value);
internal class MyLabelRenderer : IRenderLabel
context)
]);
(row > 999)
].ToString();
else
//return context["DATA_VALUE"].ToString();
try this:
protected void Chart_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { Axis yAxis = e.Grid["Y"] as Axis; Axis xAxis = e.Grid["X"] as Axis; if (yAxis == null) { return; } PrimitiveCollection primitivesToAdd = new PrimitiveCollection(); int pointCounter = 0; foreach (Primitive p in e.SceneGraph) { Line l = p as Line; if (l != null && l.p1.Y == l.p2.Y) { // this should be the x axis line l.p1.X = yAxis.startPoint.X; l.p2.X = e.ChartCore.GetChartLayer().GetOuterBounds().Right; } Text t = p as Text; if (t != null && (t.bounds.Right < yAxis.startPoint.X || t.bounds.Top > xAxis.startPoint.Y || (t.Path != null && (t.Path == "Border.Title.Grid.X" || t.Path == "Border.Title.Grid.Y")))) { Box boxToAdd = new Box(t.bounds); boxToAdd.PE.FillOpacity = boxToAdd.PE.StrokeOpacity = 0; boxToAdd.Caps = PCaps.Tooltip | PCaps.HitTest; boxToAdd.Layer = e.ChartCore.GetChartLayer(); boxToAdd.Chart = e.ChartCore.ChartType; boxToAdd.Row = boxToAdd.Column = 1000 + pointCounter++; double k; if (double.TryParse(t.GetTextString(), out k) == true) { boxToAdd.Value = double.Parse(t.GetTextString()); } else { boxToAdd.Value = t.GetTextString(); } boxToAdd.Tags = new Hashtable(); boxToAdd.Tags.Add("MY_VALUE", boxToAdd.Value); primitivesToAdd.Add(boxToAdd); } } e.SceneGraph.AddRange(primitivesToAdd.ToArray()); }
it worked fine for me. attached sample
Hi
I used the same code in line chart but it dint work. I tried to fix it but failed. Can you tell me how can I do this for linechart? What are the changes need to be done?
Thanks.
Thanks. It works fine.