Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
195
Custom Legend location
posted

Hi;

 Is it possible that I can custom the legend's location? I saw only 4 locations currently available (top, left, right, bottom), and i can  not drag the legend icon to the location I prefer, such as in the middle of the chart.

 If it is, how can i implement?

thanks ...

 

Parents
No Data
Reply
  • 28496
    Offline posted

     here's a simple example using the FillSceneGraph event to get you started.  if you are using version 7.2 or earlier, you will need to move this code into a class implementing ILayer, as the FillSceneGraph event is new to 7.3.

     

    private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e)

    {

    int legendBoxX = (int)(this.ultraChart1.Width * .7);

    int legendBoxY = (int)(this.ultraChart1.Height * .1);

    int legendBoxW = (int)(this.ultraChart1.Width * .25);

    int legendBoxH = (int)(this.ultraChart1.Height * .5);

    Box legendBox = new Box(new Rectangle(legendBoxX, legendBoxY, legendBoxW, legendBoxH));legendBox.PE.Fill = Color.Yellow;

    e.SceneGraph.Add(legendBox);

    LabelStyle legendLabelStyle = new LabelStyle();

    int legendItemX = (int)(legendBoxX + legendBoxW * .1);int legendItemY = (int)(legendBoxY + legendBoxH * .1);

     

    int legendItemW, legendItemH;

    legendItemW = legendItemH = (int)(legendBoxW * .2);

    int legendItemSpace = (int)(legendItemW * .25);

    int legendItemTextX = legendItemX + legendItemW + legendItemSpace;

    int legendItemTextW = legendBoxX + legendBoxW - legendItemTextX;

    Box legendItem1Box = new Box(new Rectangle(legendItemX, legendItemY, legendItemW, legendItemH));legendItem1Box.PE.Fill = Color.Red;

    e.SceneGraph.Add(legendItem1Box);

     

    Text legendItem1Text = new Text(new Rectangle(legendItemTextX, legendItemY, legendItemTextW, legendItemH), "Item A", legendLabelStyle);

    e.SceneGraph.Add(legendItem1Text);

    legendItemY += legendItemH + legendItemSpace;

    Box legendItem2Box = new Box(new Rectangle(legendItemX, legendItemY, legendItemW, legendItemH));legendItem2Box.PE.Fill = Color.Blue;

    e.SceneGraph.Add(legendItem2Box);

    Text legendItem2Text = new Text(new Rectangle(legendItemTextX, legendItemY, legendItemTextW, legendItemH), "Item B", legendLabelStyle);

    e.SceneGraph.Add(legendItem2Text);

    }

Children