Page 1 of 1
How to include custom legend in export?
Posted: Wed Jul 31, 2013 12:26 pm
by 15666433
Hi,
I've created a custom legend that is working very nicely with TeeChart, but I notice that when I export charts, my custom legend is not included. Is there any way to include my custom legend when exporting a TeeChart to, say, GIF, BMP or JPG format?
Thanks,
Jay
Re: How to include custom legend in export?
Posted: Thu Aug 01, 2013 8:36 am
by 10050769
Hello Jay,
Using next code to make a custom legend:
Code: Select all
private MyLegend myLegend;
private void InitializeChart()
{
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
myLegend = new MyLegend(tChart1.Chart);
tChart1.AfterDraw+=new PaintChartEventHandler(tChart1_AfterDraw);
tChart1.Series.Add(typeof(Line));
tChart1[0].FillSampleValues();
tChart1.Legend.Visible = false;
tChart1.Panel.MarginRight = 40;
button1.Click += button1_Click;
}
void button1_Click(object sender, EventArgs e)
{
tChart1.Export.Image.JPEG.Save(@"C:\CustomLegend.jpg");
tChart1.Export.Image.GIF.Save(@"C:\CustomLegend.gif");
tChart1.Export.Image.PNG.Save(@"C:\CustomLegend.png");
tChart1.Export.Image.Bitmap.Save(@"C:\CustomLegend.bmp");
}
void tChart1_AfterDraw(object sender, Graphics3D g)
{
myLegend.Draw(g, Utils.FromLTRB(tChart1.Width - 200, 100, tChart1.Width - 50, 250));
}
public class MyLegend : TeeBase
{
public MyLegend() : this((Chart)null) { }
public MyLegend(Chart c) : base(c) { }
public void Draw(Graphics3D g, Rectangle r)
{
g.Rectangle(r);
g.Font.Bold = true;
g.TextOut(r.X, r.Y, base.Chart[0].Title);
}
}
I can export correctly the Chart and custom legend. See images GIF, JPEG, results:
- CustomLegend.gif (129.29 KiB) Viewed 12033 times
- CustomLegend.jpg (110.89 KiB) Viewed 12031 times
Could you please, tell us which version of TeeChartFor.net are you using? If you use last version, could you please send us a simple code where we can reproduce your problem here?
Thanks,
Re: How to include custom legend in export?
Posted: Thu Aug 01, 2013 9:21 pm
by 15666433
I'm using the latest version of TeeChart 2013. My legend is complex with a fair number of controls and behaviors on it. It is integrated with the TeeChart simply by adding it the Controls collection of the chart. I had hoped that simply adding it to that collection would be sufficient for TeeChart to render it as part of the chart when exporting an image.
The technique you describe would be cumbersome for me because I would have to reverse engineer custom rendering logic to match the current placement and properties of all the elements on my control. This seems like a lot of excessive effort when all I want is for the exported image to look exactly like the screen.
Is there a simpler way I can TeeChart to simply render my control as it is currently displayed on screen as part of the exported image?
Re: How to include custom legend in export?
Posted: Fri Aug 02, 2013 10:37 am
by 10050769
Hello JCincotta,
I'm using the latest version of TeeChart 2013. My legend is complex with a fair number of controls and behaviors on it. It is integrated with the TeeChart simply by adding it the Controls collection of the chart. I had hoped that simply adding it to that collection would be sufficient for TeeChart to render it as part of the chart when exporting an image.
I suggest you try to implementing your custom serialization and deserialize for your legend control, so, you can export it. I recommend you taking a look in Tutorial19 - Custom Serialization.
The technique you describe would be cumbersome for me because I would have to reverse engineer custom rendering logic to match the current placement and properties of all the elements on my control. This seems like a lot of excessive effort when all I want is for the exported image to look exactly like the screen.
Is there a simpler way I can TeeChart to simply render my control as it is currently displayed on screen as part of the exported image?
To get the position and the size of Legend, can be very useful for you use
GetLegendRect event that provides a mechanism to supply the desired Rectangle Legend dimensions and placement or the
GetLegendPos event that can be used to specify fixed Legend items X Y coordinates.
If it doesn't help, could you please send us your project, because we can try to find a solution for you ?
I hope will helps.
Thanks,
Re: How to include custom legend in export?
Posted: Fri Aug 02, 2013 3:24 pm
by 15666433
Hi Sandra,
Thank you for your offer to take a look at my code. I've created a simple sample project that populates TeeChart with my custom legend. The form already includes a button to export an image and you'll see that it does not include the custom legend.
Thanks in advance for your assistance with getting export functionality working with my custom legend.
Thanks,
Jay
Re: How to include custom legend in export?
Posted: Mon Aug 05, 2013 12:27 pm
by 10050769
Hello JCincotta,
I achieve export the Chart with your legend, exporting the WinForm Form. Please, check if the modification I have made in your project works in your end.
I hope will helps.
Thanks,
Re: How to include custom legend in export?
Posted: Mon Aug 05, 2013 5:16 pm
by 15666433
Hi Sandra,
How could we make this approach work with the Export tab of Steema.TeeChart.Editor?
We expose your editor to our users allowing them to customize charts, especially for reporting purposes. It seems to me, that any of your customers that extend TeeChart with custom annotations or legends would want the underlying TChart.Export.Image.xxx.Save(...) methods to exhibit WYSIWYG behavior by implementing the BitMap technique you suggest.
Would you agree that this is a valid feature request? Anything we implement would not extend the Steema.TeeChart.Editor, so unless you implement this within TeeChart, the Export feature of the Editor will not behave as users would expect.
Thanks,
Jay
Re: How to include custom legend in export?
Posted: Tue Aug 06, 2013 11:58 am
by 10050769
Hello JCincotta,
First, you must know that if you add any tools as annotation, legend tool using editor, TeeChart has mechanisms that allow you export without problems the extra elements (annotation, extralenged) you add in the Chart, using our editor. You can achieve export in same way your custom components, always, if these inherit from TeeChart components (Series,Tools, etc).
Second, weeing your code, I have realized you use a external control that doesn't inherit by TeeChart components, moreover, when open the editor this control doesn't appear in any list of components (tools,series) and isn't possible add it in the chart, using chart editor. For this reason, I understand you use your own controls that don't inherit of TeeChart components and you want TeeChart export all extra controls automatically, although these don't inherit by TeeChart. We consider your request and I have added it as a feature request with number [TF02016679] to be consider its inclusion in future versions of TeeChartFor.Net.
Thanks,
Re: How to include custom legend in export?
Posted: Tue Aug 06, 2013 1:01 pm
by 15666433
My control just uses standard Winform controls: Label, Checkbox, Panel, UserControl. As to the behavior of my control in the editor, it only shows empty panels because the nature of my requirements are such that I need to add labels and checkboxes dynamically at run-time.
Are there some TeeChart equivalent controls I could use instead that will export properly in the current version?
Re: How to include custom legend in export?
Posted: Tue Aug 06, 2013 3:18 pm
by 10050769
Hello JCincotta,
My control just uses standard Winform controls: Label, Checkbox, Panel, UserControl. As to the behavior of my control in the editor, it only shows empty panels because the nature of my requirements are such that I need to add labels and checkboxes dynamically at run-time.
Are there some TeeChart equivalent controls I could use instead that will export properly in the current version?
At the moment isn't possible achieve equivalent controls as you want, with the TeeChart components. I have added your request about export your own controls using editor as told you in previous post.
On the other hand, currently to treat your both problems exportation (without editor) and add own component in the list of editor components, I recommend do next:
In the case of exportation, you can try to implement your exportation using custom serialization and deserialization as do in the Tutorial19 - Custom Serialization. In this tutorial you can find a simple example that can help you to include your custom legend in the TChart exportation.
In the case of add your own controls in the list of components of TeeChart, I recommend you try to create custom tools and do something similar as do in custom series to registered as is explained in this
thread.
The previous suggestion, are ideas can help you to achieve as you want using TeeChart, at the moment.
Thanks,