Export legend only to an image

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Adam
Newbie
Newbie
Posts: 17
Joined: Tue Nov 06, 2012 12:00 am

Export legend only to an image

Post by Adam » Wed Jan 16, 2013 9:56 am

Hi,

Is there any option to export legend box to an image?
I know I can export any chart with/without the legend but I would like to export just legend box (if visible).
I use TeeChart for WPF.

regards, Adam

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Export legend only to an image

Post by Sandra » Wed Jan 16, 2013 3:26 pm

Hello Adam,
Is there any option to export legend box to an image?
No, there isn't. If you want get the legend box, you must export the control Chart. When you have the image, you can manipulate it as you want. To achieve this, you can use GetLegendRect event as do in next code:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }

    private Bitmap chartBmp;

    private void InitializeChart()
    {
      tChart1.Series.Add(new Steema.TeeChart.Styles.Bar()).FillSampleValues();

      chartBmp = tChart1.Bitmap;

      tChart1.GetLegendRect += tChart1_GetLegendRect;
    }

    void tChart1_GetLegendRect(object sender, Steema.TeeChart.GetLegendRectEventArgs e)
    {
      Rectangle cropRect = e.Rectangle;
      Bitmap legendImg = new Bitmap(cropRect.Width, cropRect.Height);

      using (Graphics g = Graphics.FromImage(legendImg))
      {
        g.DrawImage(chartBmp, new Rectangle(0, 0, legendImg.Width, legendImg.Height),
                         cropRect,
                         GraphicsUnit.Pixel);
      }

      legendImg.Save(@"c:\temp\legend.png");
    }
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply