Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

ChartDrawItemEvent

Last post 05-21-2008 3:32 by jeffmbrake. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 01-10-2008 11:22

    ChartDrawItemEvent

    Hi

     I'm trying to implement the ChartDrawItemEvent event so that I can draw custom colours on my chart (ColorModel isn't flexible enough for my needs). But the e.Primitive DataPoint property is always null. How do I set that in code? and what value do I need to assign?

     Thanks

    • Post Points: 20
  • 01-10-2008 14:57 In reply to

    Re: ChartDrawItemEvent

    Answer

    DataPoint property will be null for most scenarios, except when the primitive represents a single data point. For example, for a column chart, each box represents one datapoint, so DataPoint property will be set. For a line chart a polyline primitive consists of more than one data point, therefore DataPoint property is null and you have to look into the Points collection of the polyline to get the points. I'm not sure why you need the DataPoint property to be set. Have you tried using CustomSkin at your color model?

    • Post Points: 20
  • 01-11-2008 1:58 In reply to

    Re: ChartDrawItemEvent

    Thanks for the information. How do I use the CustomSkin? I would like to use certain colours that I have for each type of data point. Each data point has a property called Style (of which there are many) and i would like to use a specific color for each one. My attempts at using the ColorModel have so far been unsuccessful, mainly because the style property is not the data value of the point.

    • Post Points: 20
  • 01-11-2008 9:59 In reply to

    Re: ChartDrawItemEvent

    This link has a pretty good explanation of using custom skin:
    http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/Chart_Custom_Skins_and_Paint_Elements.html

    Basically, you set the ColorModel.ModelStyle to CustomSkin and add instances of PaintElement to ColorModel.Skin.PEs collection. Each paint element can be customized. Our DataPoint class doesn't have a Style property (you may be using your own class here?)

    Our primitives are customized through the PE property, because for certain primitives that have more than one data point, it really wouldn't make much sense to set colors on the data point and expect the entire primitive to change colors. What type of chart are you using? It might help if you included a picture of your chart. Otherwise, it's pretty hard to speculate on what approach would work best.

    • Post Points: 20
  • 05-09-2008 18:52 In reply to

    Re: ChartDrawItemEvent

    Sorry to hijack your thread, but I'm running across the same issue. I have an ScatterChart that I need to modify so that it paints each data point with a different color depending on a given formula.

    If I try the ColorModel solution in this case, all the dots use the first PE property (since the PointSet probably counts as a single row), but if I do it in a PointChart3D chart I get the expected results. Is there a way to paint each data point in a custom way for an ScatterChart?

    • Post Points: 35
  • 05-12-2008 10:21 In reply to

    Re: ChartDrawItemEvent

    The 2D scatter chart uses pointset primitives,which unfortunately, don't provide a way to color individual data points. You can work around this by adding Symbol primitives directly on top on the existing data points using FillSceneGraph event of the chart.

    Try following the example in this link, except instead of adding a Box primitive it would be a Symbol.
    http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/Chart_Modify_Scene_Graph_Using_FillSceneGraph_Event.html

    • Post Points: 20
  • 05-15-2008 10:30 In reply to

    Re: ChartDrawItemEvent

    Thanks for the info. Does this also work on version 6.3? I notice that there is no Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs with my version.

     Also, the current code we have uses poinset primitives. When you say I need to add symbols on top, does that mean override the pointsets???

    I am using a ChartLayer class which implements the ILayer class, and in there I have a FillSceneGraph(SceneGraph scene) method (this is legacy code which I did not write, see below):

     How would I implement different colours depending on the strategyId???

    public void FillSceneGraph(SceneGraph scene)

    {

    ChartData chart = (ChartData)((Control)ChartComponent).Tag;

    IDictionary pointSetData = chart.PointSetData;

    if (pointSetData == null)

    {

    foreach (Primitive p in scene)

    {

    PointSet points = p as PointSet;

    if (points != null)

    {

    int counter = GetRow(points);

    if (counter == 0)

    {

    points.drawColor =
    Color.LimeGreen;

    points.fillColor = Color.LimeGreen;

    points.icon = SymbolIcon.X;points.iconSize = SymbolIconSize.Large;

    }

    else if (counter == 1)

    {

    points.drawColor = Color.Blue;

    points.fillColor = Color.Blue;

    points.icon = SymbolIcon.Triangle;

    points.iconSize = SymbolIconSize.Medium;

    }

    else if (counter == 2)

    {

    points.drawColor =
    Color.Red;

    points.fillColor = Color.Red;

    points.icon = SymbolIcon.Diamond;points.iconSize = SymbolIconSize.Medium;

    }

    else

    {

    points.drawColor = Color.Yellow;

    points.fillColor = Color.Yellow;

    points.icon = SymbolIcon.Circle;points.iconSize = SymbolIconSize.Medium;

    }

    }

    }

    }

    else

    {

    ArrayList newItems = new ArrayList();foreach (Primitive p in scene)

    {

    PointSet points = p as PointSet;

    if (points != null)

    {

    // Use pointSetData

    int counter = GetRow(points);if (counter == 0)

    {

    // special case

    points.drawColor = Color.LimeGreen;

    points.fillColor = Color.LimeGreen;

    points.icon = SymbolIcon.X;

    points.iconSize = SymbolIconSize.Large;

    continue;

    }

    PointInfo pi = pointSetData[counter] as PointInfo;if (pi != null)

    {

    short styleId = model.AnalysisModel.ChartProvider.StyleId(counter);

    short strategyId = model.AnalysisModel.ChartProvider.StrategyId(counter);

    points.drawColor = GetStrategyColor(strategyId);

    points.fillColor = GetStrategyColor(strategyId);

    points.icon =
    ChartDataHelper.GetStyleIcon(styleId);

    points.iconSize = SymbolIconSize.Medium;

    }

    else

    {

    points.drawColor =
    Color.Pink;

    points.fillColor = Color.Pink;

    points.icon = SymbolIcon.Character;

    points.character = '#';

    points.iconSize = SymbolIconSize.Medium;

    }

    // Make different color around an icon

    if (points.icon != SymbolIcon.Plus)points.drawColor = Color.Black;

     

    // Add labels

    if (showLabels)

    {

    foreach (Primitive dp in points.GetPrimitives())

    {

    DataPoint dataP = dp as DataPoint;if (null != dataP)

    {

    Point pnt = dataP.point;

    pnt.Offset(3, -3);

    string label = model.GetDataPointLabel(dataP.Row);if (dataP.Row != 0)

    {

    short strategyId = model.AnalysisModel.ChartProvider.StrategyId(dataP.Row);

    dataP.PE.Fill = GetStrategyColor(strategyId);

    dataP.drawColor = GetStrategyColor(strategyId);

    }

    FontStyle fontStyle = FontStyle.Regular;Color fontColor = Color.Black;if (-1 != label.IndexOf(" [NOTE: "))

    {

    fontColor = Color.Red;

    label = label.Substring(0, label.IndexOf(" [NOTE: "));

    }

    Text text = new Text(pnt, label, new LabelStyle());text.labelStyle.Font = new Font(text.labelStyle.Font.FontFamily, 7, fontStyle, GraphicsUnit.Point);

    text.labelStyle.FontColor = fontColor;

    text.DataPoint = (
    IDataPoint)dataP;

    newItems.Add(text);

    }

    }

    }

    }

    }

    // Now add those new items

    foreach (Text t in newItems)

    {

    scene.Add(t);

    }

    }

    }

     

    Thanks

    • Post Points: 20
  • 05-20-2008 10:11 In reply to

    Re: ChartDrawItemEvent

    You don't need to override the pointset. Picture a drawing surface with existing pointsets. Now take any of the indexed points of a pointset and draw a symbol at the point's coordinates. Something like this:

    //somewhere in the foreach(p in scene) loop store a reference to your pointset to make it accessible outside the loop; let's call it myPointSet.

    //this will draw a large red circle over the 2nd point in the pointset
    Point point = myPointSet.points[1].point;
    Symbol symbol = new Symbol(point, SymbolIcon.Circle, SymbolIconSize.Large);
    symbol.PE.Fill =
    Color.Red;
    scene.Add(symbol);

    • Post Points: 5
  • 05-21-2008 3:32 In reply to

    ChartDrawItemEvent

    Hi David

    I managed to get the chart to draw each point with a colour of my choosing. I did not use the colour model, as that requires the use of a ColorPalette which overrides the colors you chose.

    I don't know which version you are using (we have v6.3 here), but you need to implement the FillSceneGraph event for the chart. In there you can get all points drawn on the chart, and then to override the color of each one just use the point.PE.Fill to set the color depending on your formula.

    Hope that helps.

    Jeff

    • Post Points: 5
Page 1 of 1 (9 items)
Powered by Community Server (Commercial Edition), by Telligent Systems