How to include custom legend in export?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
JCincotta
Newbie
Newbie
Posts: 8
Joined: Fri Jun 28, 2013 12:00 am

How to include custom legend in export?

Post by JCincotta » Wed Jul 31, 2013 12:26 pm

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

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

Re: How to include custom legend in export?

Post by Sandra » Thu Aug 01, 2013 8:36 am

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
CustomLegend.gif (129.29 KiB) Viewed 12187 times
CustomLegend.jpg
CustomLegend.jpg (110.89 KiB) Viewed 12185 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,
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

JCincotta
Newbie
Newbie
Posts: 8
Joined: Fri Jun 28, 2013 12:00 am

Re: How to include custom legend in export?

Post by JCincotta » Thu Aug 01, 2013 9:21 pm

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?

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

Re: How to include custom legend in export?

Post by Sandra » Fri Aug 02, 2013 10:37 am

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,
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

JCincotta
Newbie
Newbie
Posts: 8
Joined: Fri Jun 28, 2013 12:00 am

Re: How to include custom legend in export?

Post by JCincotta » Fri Aug 02, 2013 3:24 pm

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
Attachments
ExportSample.zip
Sample project for testing export of custom legend
(70.75 KiB) Downloaded 451 times

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

Re: How to include custom legend in export?

Post by Sandra » Mon Aug 05, 2013 12:27 pm

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.
ExportSample.zip
(66.34 KiB) Downloaded 543 times
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

JCincotta
Newbie
Newbie
Posts: 8
Joined: Fri Jun 28, 2013 12:00 am

Re: How to include custom legend in export?

Post by JCincotta » Mon Aug 05, 2013 5:16 pm

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
Attachments
Steema.TeeChart.Editor.png
Steema.TeeChart.Editor
Steema.TeeChart.Editor.png (63.01 KiB) Viewed 12127 times

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

Re: How to include custom legend in export?

Post by Sandra » Tue Aug 06, 2013 11:58 am

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,
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

JCincotta
Newbie
Newbie
Posts: 8
Joined: Fri Jun 28, 2013 12:00 am

Re: How to include custom legend in export?

Post by JCincotta » Tue Aug 06, 2013 1:01 pm

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?

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

Re: How to include custom legend in export?

Post by Sandra » Tue Aug 06, 2013 3:18 pm

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,
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