ChartControl Serializable?

Hi,

I am trying to utilize the chartControl but one of the features I need is to save the chart (especially the styles and properties). Is this control able to be serialized and deserialized using XML, or perhaps is there another way to save and load the visual properties of the chart?

I saw a similar question asked here on the forums years ago and it said that this feature was to be added a month later but no other update was in the thread.

Thank you!

24 Replies

SK Sanjith Kesavan Syncfusion Team February 26, 2018 09:40 AM UTC

Hi Travis, 

Thanks for contacting Syncfusion support. We have analyzed your query and prepared sample as per your requirement. We can achieve your requirement using ChartTemplate.Load and ChartTemplate.Save method. Using ChartTemplate.Load you can deserialize the xml file and load it as chart. Using ChartTemplate.Save you can serialize the chart and save it as xml file. In this sample, we have load the chart from the xml file. In the template folder, we are already having 6 xml files. As per the button clicked in the sample, corresponding xml file is serialized and as per the serialized data chart is loaded. Please find the below code example. 

[C#] 
string currentTemplate = "Column_Square.xml"; 
private void ChartType_Click(object sender, EventArgs e) 
{ 
   if (chartButton == this.buttonAdv2) 
      { 
         this.toolStripStatusLabel1.Text = filePath + "\\Column_Square.xml"; 
         this.buttonAdv2.State = ButtonAdvState.Pressed; 
         this.buttonAdv2.Enabled = false; 
         currentTemplate = "Column_Square.xml"; 
      } 
   ChartTemplate.Load(this.chartControl1, currentTemplate); 
} 

Above code will load the chart from the “Column_Square.xml” file. To save the chart as new template kindly follow the below code. 

[C#] 
//Saves file to a new template 
saveTemplateFile = "Template" + ".xml"; 
ChartTemplate.Save(this.chartControl1, saveTemplateFile); 

Using the above code chart can be saved as new template (xml) file inside the bin\Debug folder. In the below link, we have attached sample for your reference.  
Sample link: 

Kindly check the sample and let me know if you have any other concern. 

Thanks, 
Sanjith. 




SK Sanjith Kesavan Syncfusion Team February 26, 2018 11:55 AM UTC

  
Hi Travis, 

Find the sample from the below link 
Sample link: chart 

Thanks, 
Sanjith. 



TC Travis Chambers February 28, 2018 03:11 AM UTC

Fantastic, thank you!

Also, I noticed that the gradientLabel control can be serialized for the backcolor properties. However, the online documentation has no mention of how to deserialize, only serialize. I have tried to do so using the "BackgroundColor.ReadXML" property but I am apparently doing something wrong. How is the gradientLabel deserialized?

Thanks!


KJ Keerthana Jegannathan Syncfusion Team February 28, 2018 08:45 AM UTC

Hi Travis, 
 
Thanks for your update. 
 
In GradientLabel, you can deserialize the serialized background color using the “Deserialize” function of the XmlSerializer. We have prepared a sample in which we have serialized and deserialized the background color of the GradientLabel and it can be downloaded from below location. 
 
 
Regards, 
 
Keerthana J 



TC Travis Chambers June 5, 2018 05:06 PM UTC

Good afternoon,

Using the sample in this thread to save and load a chart template works well, however each time you save it pops up with a message asking if you want to save visual styles only or not. Is there a way to disable this message box and programmatically state whether or not to save styles only?

thanks.


GS Gokul Sainarayanan Syncfusion Team June 6, 2018 07:31 AM UTC

Hi Travis,

Thanks for the update.

We can programmatically save the chart in template without showing the message box using the scan and save method of ChartTemplate instance. We have modified the sample in our previous update and it can be downloaded from the following link

http://www.syncfusion.com/downloads/support/directtrac/136102/ze/Chart_Template-1681414270  

Please refer the following code snippet to achieve this

[C#]  
                 //ChartTemplate.Save(this.chartControl1, currentTemplate); 
                ChartTemplate template = new ChartTemplate(this.chartControl1.GetType());                   
                //Specify whether chart series should also be saved in template 
                //Value for this property was previously obtained from user through message box 
                ChartTemplate.StoreAllProperties = false;  
                //Scan the chart control 
                template.Scan(this.chartControl1);   
                //Save the chartcontrol in XML file 
                template.Save(currentTemplate);   


Regards,
Gokul S


TC Travis Chambers June 10, 2018 03:32 AM UTC

It appears that serializing the chartcontrol does not save certain, important properties. In particular the series chart types and the individual series colors are not saved (although the general color pallet is saved).

Thank you.  


AT Anandaraj T Syncfusion Team June 11, 2018 10:12 AM UTC

Hi Travis, 

Thanks for the update. 

We suggest you to use ScanSeries and SaveSeries methods of ChartTemplate to serialize the properties of ChartSeries in the template. We have modified the sample in our previous update and it can be downloaded from the following link 

Please refer the following code snippet to achieve this 

[C#] 
 
                saveTemplateFile = "Template" + templateCount.ToString() + ".xml"; 
 
                MemoryStream stream = new MemoryStream(); 
                ChartTemplate.StoreAllProperties = true; 
                ChartTemplate template = new ChartTemplate(typeof(ChartControl)); 
 
                template.Scan(this.chartControl1); 
                template.Save(stream); 
 
                foreach (ChartSeries series in this.chartControl1.Series) 
                { 
                    template.ScanSeries(series); 
                    template.SaveSeries(stream); 
                } 
 
                byte[] buffer = new byte[stream.Length - 1 + 1]; 
                stream.Position = 0; 
                stream.Read(buffer, 0, System.Convert.ToInt32(stream.Length)); 
                stream.Dispose(); 
                stream.Close(); 
                File.WriteAllBytes(saveTemplateFile, buffer); 
 

Please let us know if you have any concern. 

Regards, 
Anand 



TC Travis Chambers June 11, 2018 12:02 PM UTC

This is good, thank you. It does now successfully save the chart type and series colors. However, is there a way to do this same thing but without saving the data? I need to be able to load the xml properties after new data has been selected and applied to the chart without reverting back to the original data.

Thanks.


AT Anandaraj T Syncfusion Team June 12, 2018 09:14 AM UTC

Hi Travis, 

Thanks for the update. 

Currently, support for serializing the series appearance and styles without the data points is not available. We have already added it to our feature request list, which will be available in any of our upcoming release. You can also check our website periodically to know the status of the feature. 

Please let us know if you have any concern. 

Regards, 
Anand


TC Travis Chambers June 12, 2018 11:57 AM UTC

Thank you for your response!In the meantime I will simply rethink my application design and try to get around my issue that way.

Thanks.


SK Sanjith Kesavan Syncfusion Team June 13, 2018 11:25 AM UTC

Hi Travis, 

Most welcome. We will also try the possible way to sort the issue at our end.  

Thanks, 
Sanjith. 



TC Travis Chambers June 13, 2018 12:29 PM UTC

Thank you Sanjith!

Also, I have found another issue with the serialization that I would like to bring to your attention so that you can look into it. It appears that the "Shape" properties do not serialize. That includes the points in a scatter plot. If you change the size of the points in the scatter plot it will revert back to the default size after re-loading (de-serializing) the chart. For non-scatter plot charts, if you add a shape it will simply disappear when re-loaded.

Thanks!


AT Anandaraj T Syncfusion Team June 14, 2018 12:21 PM UTC

Hi Travis, 

Thanks for the update. 

The reported issue occurs due to not serializing the complex property Symbol in chart series style. So symbol related information like shape, size, etc.., will not be present in the saved template and this issue will occur when loading it. In our current implementation, we do not have support for serializing all the complex properties in chart i.e. completely serializing the chart is not available. We have already added it to our features request list, which will be available in any of our upcoming release. You can also check our website periodically to know the status of the feature. 

Please let us know if you have any concern. 

Regards, 
Anand 



TC Travis Chambers June 15, 2018 03:19 PM UTC

Thank you for the update! I am glad to hear that this feature will be included in the future.

Likewise, I have found that my x-axis labels do not serialize. To set my labels I have had to use the "ChartFormatAxisEventArgs" because when trying to set the x-axis this way:

ChartDataBindAxisLabelModel dataLabelsModel = new ChartDataBindAxisLabelModel(dgv.DataSource, "Column1");

dataLabelsModel.LabelName = "Column1";

It does not set the labels with the text entries in Column1 but instead simply leaves them 0, 1, 2, 3, etc.

IS the ChartFormatAxisEvent simply not read for serializing? If the datalabelsmodel method does allow serializing, do you have any ideas why that method is not woring?


Thanks!





AT Anandaraj T Syncfusion Team June 18, 2018 07:37 AM UTC

Hi Travis, 

Thanks for the update. 

Query #1: IS the ChartFormatAxisEvent simply not read for serializing? 

When serializing the chart control, only the properties of chart will be serialized and events will not be serialized. So changes made in ChartFormatAxisEvent will not be reflected in a deserialized chart. 

Query #2: If the datalabelsmodel method does allow serializing, do you have any ideas why that method is not woring? 

We can serialize and deserialize the ChartDataBindAxisLabelModel assigned to LabelsImpl property of ChartAxis. We have prepared a simple sample for this requirement and it can be downloaded from the following link 

Please refer the following code snippet to achieve this 

[C#] 
 
            ChartDataBindAxisLabelModel labelModel = new ChartDataBindAxisLabelModel(data); 
            labelModel.LabelName = "Labels"; 
 
            chartControl1.Indexed = true; 
            chartControl1.PrimaryXAxis.LabelsImpl = labelModel; 
            chartControl1.PrimaryXAxis.ValueType = ChartValueType.Custom; 
            chartControl1.PrimaryXAxis.TickLabelsDrawingMode = ChartAxisTickLabelDrawingMode.UserMode; 
 

Please let us know if you have any concern. 

Regards, 
Anand


TC Travis Chambers June 18, 2018 01:33 PM UTC

Thank you for the update. This, however, doesn't seem to solve the problem. I am setting the x-axis labels in this way, but they are not serializing. When de-serializing the x-axis labels appear blank. The attached sample doesn't appear to serialize the x-axis labels either. By default the column chart has labels of A1, A2, A3, etc. but those are added in after the XML doc is loaded. If you comment out the manual setting of these the labels revert to the indexes 1, 2, 3, 4, etc.

Thanks!




AT Anandaraj T Syncfusion Team June 19, 2018 06:25 AM UTC

Hi Travis, 

Sorry for the inconvenience caused. 

We have analyzed the serialized template and found that the ChartAxisDataBindModel is not serialized. As we have used the same chart for serializing and deserializing, the property LabelsImpl of PrimryXAxis was not changed in chart before and after serialization. So in our sample, the labels are changed after reloading the saved template. But if you use a different chart for deserialization whose x-axis does not bound to ChartAxisDataBindModel, then default labels will appear in chart. 

As of now, support for serializing the ChartAxisDataBindModel bound to the axis labels is not available. We have considered this as a new feature request and added it to our features request list, which will be available in any of our upcoming releases. You can also check our website periodically to know the status of the feature. 

Please let us know if you have any concern. 

Regards, 
Anand 



TC Travis Chambers August 18, 2018 09:15 PM UTC

Good day, I just wanted to follow up to see if the feature of serializing chartcontrol completely (all properties) is still on the feature list and if it will be available soon?

Thanks! 


MK Muneesh Kumar G Syncfusion Team August 20, 2018 07:12 AM UTC

Hi Travis, 
 
We unable to provide the exact timeline for these features, but you can randomly visit our website to check the status of these features. 
 
Thanks,
Muneesh Kumar G.
 
 
 



TC Travis Chambers June 14, 2019 01:29 PM UTC

Good day,

I wanted to follow-up on this since it has been almost a year since the last response. Has there been an update on the ability to better serialize chartcontrols with ALL available properties.

Currently, saving and loading from XML does not appear to save:

  • Any Symbol appearance property
  • the chart type for a second series (I.e. if series[0] is spline and series[1] is set to column, reloading sets both series to spline)
  • Y-axis for second series (i.e. if series[1] is set on a new, secondary y-axis, reloading puts both series on the primary axis)
  • Label properties for second series

I could probably save all of the additional properties to a hidden gridcontrol and then loop through the grid and save and apply these settings from the grid, but of course this creates a lot more work and impacts performance as it adds a lot of looping.

So, ideally, it would be wonderful is serializing the chartcontrols would capture all properties and then reloading would load the chart exactly as it was when saved.


Any updates would be very much appreciated.

Thanks!



BP Baby Palanidurai Syncfusion Team June 17, 2019 05:53 AM UTC

Hi Travis, 

Thanks your update. 

We have analyzed your query. As of now, we have implemented to save the chart series in template with, without data points and with series style for single series only. And we haven’t implemented to serialize multiple series. As of now we don’t have immediate plans to implement this support. Based on the priority, this feature will be included in any one of our upcoming release. We appreciate your patience until then. 

Kindly find the below sample link to serialize the chart symbols, 
  
Kindly revert us, if you have any concerns. 

Regards, 
Baby. 
  
  



TC Travis Chambers June 19, 2019 11:43 AM UTC

Thank you for the update. This is a bit disappointing, but I can store property values in a hidden gridcontrol and loop through each row to apply the properties to the charts as they load. This is not very convenient and will likely ding performance a bit with all the looping, but it does work.

I definitely do recommend your team consider supporting all series when serializing in the future. It is very common to have multiple series (at least 2 series) in charts and having this functionality would give Syncfusion a more complete and dynamic chartcontrol.

Thanks!


BP Baby Palanidurai Syncfusion Team June 20, 2019 03:14 PM UTC

Hi Travis, 

Sorry for the inconvenience. 

We can understand the need of this feature. But as of now, we couldn’t provide the exact timeline for this feature due to the progress of other features. Based on the other features priority, we will plan to start to implement this feature as soon as possible and will include this in any one of our upcoming release. We will let you know once we start to implement this feature. We appreciate your patience until then. 
 
Regards, 
Baby.

Loader.
Up arrow icon