Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clone microsoft chart control?

What's the recommended way of cloning an object of Microsoft Chart Control? Because it is a third-party library, I can't use the solution mentioned here as I can't mark the object as serializable.

Preferably, I would not like to introduce any third party controls to clone the chart unless if it is absolutely impossible to do so without one.

like image 355
l46kok Avatar asked Oct 18 '25 17:10

l46kok


1 Answers

You should not need to mark it as serializable as the charts already have the ability to be serialized. Check out this MS Charts Documentation for more information

From here, you can serialize the chart into a string, then immediately deserialize the string into a new instance of the chart object. This would act similarly to cloning, and appears to be what the answer mentioned in your quesiton is doing. It is probably not the most efficient method for doing this, but it will work

EDIT

This code is unteseted but should work (Be fairly accurate for how to accomplish this)

Chart chart1 = new Chart();
//Enter your chart building code here
System.IO.MemoryStream myStream = new System.IO.MemoryStream();
Chart chart2 = new Chart();
chart1.Serializer.Save(myStream);
chart2.Serializer.Load(myStream);
like image 190
Dan Drews Avatar answered Oct 20 '25 09:10

Dan Drews



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!