4

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.

Community
  • 1
  • 1
TtT23
  • 6,876
  • 34
  • 103
  • 174
  • Why do you need to clone the chart? – Eric Brown Jul 26 '13 at 07:00
  • @EricBrown I'm implementing a feature where a user can double click an existing chart to produce a "Detail view" on it, meaning that I first need to get an identical copy of the existing chart then add/modify properties on the cloned chart. – TtT23 Jul 26 '13 at 07:13

2 Answers2

7

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);
Dan Drews
  • 1,966
  • 17
  • 38
0

This does not exactly answer your question but it could help you in implementing your feature.You could use the Drill Down feature of Chart control to produce a detailed view of the part of the chart the user has clicked. Refer the samples environment of mschart.

Joe Vi
  • 473
  • 4
  • 10
  • Thanks for the suggestion, but not exactly what I'm looking for. I still need to clone the chart for other reasons besides detail view, it just happens to be one of them. – TtT23 Jul 28 '13 at 13:50