Page 1 of 1
Export legend only to an image
Posted: Wed Jan 16, 2013 9:56 am
by 15663950
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
Re: Export legend only to an image
Posted: Wed Jan 16, 2013 3:26 pm
by 10050769
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,