This topic shows you how to add/remove primitives to/from the chart before the chart is rendered using the FillSceneGraph event. Using this event eliminates the need to create a custom layer class.
Note: This topic assumes that you already created a chart. For information on how to create a chart, see Getting Started with Chart.
When you save and run your application after completing the following steps, your chart should look similar to the following image:
To modify the scene graph using FillSceneGraph event:
- Before you start writing any code, you should place using/Imports directives in your code-behind so you don't need to always type out a member's fully qualified name.
In Visual Basic:
ImportsInfragistics.UltraChart.Core.ColorModelImportsInfragistics.UltraChart.Core.UtilImportsInfragistics.UltraChart.Core.LayersImportsInfragistics.UltraChart.Core.PrimitivesImportsInfragistics.UltraChart.DataImportsInfragistics.UltraChart.ResourcesImportsInfragistics.UltraChart.Resources.AppearanceImportsInfragistics.UltraChart.Resources.EditorImportsInfragistics.UltraChart.Shared.StylesIn C#:
usingInfragistics.UltraChart.Core;usingInfragistics.UltraChart.Core.ColorModel;usingInfragistics.UltraChart.Core.Util;usingInfragistics.UltraChart.Core.Layers;usingInfragistics.UltraChart.Core.Primitives;usingInfragistics.UltraChart.Data;usingInfragistics.UltraChart.Resources;usingInfragistics.UltraChart.Resources.Appearance;usingInfragistics.UltraChart.Resources.Editor;usingInfragistics.UltraChart.Shared.Styles; - Create the FillSceneGraph event.
In Visual Basic:
Private SubUltraChart1_FillSceneGraph(ByValsenderAsSystem.Object, _ByValeAsInfragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs) _HandlesUltraChart1.FillSceneGraphIn C#:
private voidultraChart1_FillSceneGraph(objectsender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) - Get the x and y axes values, as you will need them for mapping functionality.
In Visual Basic:
DimxAxisAsIAdvanceAxis =CType(e.Grid("X"), IAdvanceAxis)DimyAxisAsIAdvanceAxis =CType(e.Grid("Y"), IAdvanceAxis)In C#:
IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"]; IAdvanceAxis yAxis = (IAdvanceAxis)e.Grid["Y"]; - Make sure that axes values were actually retrieved. This needs to be done because by design the chart will fire the FillSceneGraph event twice. The first time is in early pre-rendering, and the second time is before it actually renders. The first time there is not enough information available to the chart to make the above code actually have values in it, so if you went to use those values in pre-render firing of the event you would get exceptions.
In Visual Basic:
IfxAxisIs Nothing OryAxisIs Nothing ThenReturnEnd IfIn C#:
if(xAxis ==null|| yAxis ==null)return; - Create a Text Primitive and set the following values:
- Color -- Red
- Bounds
- X-axis -- 8
- Y-axis -- 10
- Text -- Sample Text
In Visual Basic:
Dim[text]As New[Text]() [text].PE.Fill = Color.Red [text].bounds =NewRectangle(CInt(xAxis.Map(8)),CInt(yAxis.Map(10)), 100, 20) [text].SetTextString("Sample Text")In C#:
Text text =newText(); text.PE.Fill = Color.Red; text.bounds =newRectangle((int)xAxis.Map(8), (int)yAxis.Map(10), 100, 20); text.SetTextString("Sample Text"); - Add the text Primitive to the SceneGraph.
In Visual Basic:
e.SceneGraph.Add([text])In C#:
e.SceneGraph.Add(text); - Create a Box Primitive and set the following values:
- Color -- Blue
- Stroke Color -- Red
- Stroke Width -- 3
- Row -- 0
- Column -- 0
- Layer -- GetChartLayer()
- Chart -- ChartType
- Value -- 42
- Caps -- PCaps.HitTest | PCaps.Tooltip
In Visual Basic:
DimboxAs NewBox(NewRectangle( _CInt(xAxis.Map(5)),CInt(yAxis.Map(10)), 70, 20)) box.PE.Fill = Color.Blue box.PE.Stroke = Color.Red box.PE.StrokeWidth = 3 box.Row = 0 box.Column = 0 box.Layer = e.ChartCore.GetChartLayer() box.Chart =Me.UltraChart1.ChartType box.Value = 42 box.Caps = PCaps.HitTestOrPCaps.TooltipIn C#:
Box box =newBox(newRectangle( (int)xAxis.Map(5), (int)yAxis.Map(10), 70, 20)); box.PE.Fill = Color.Blue; box.PE.Stroke = Color.Red; box.PE.StrokeWidth = 3; box.Row = 0; box.Column = 0; box.Layer = e.ChartCore.GetChartLayer(); box.Chart =this.ultraChart1.ChartType; box.Value = 42; box.Caps = PCaps.HitTest | PCaps.Tooltip; - Add the Box Primitive to the SceneGraph.
In Visual Basic:
e.SceneGraph.Add(box)In C#:
e.SceneGraph.Add(box); - Save and run your application.
