Example 25: Serialization demo
In version 10.3, Super
2d/3d Graph Library introduced a new
internal utility class "SettingsFactory"
that can be used to serialize/deserialize a
chart object.
Now you can quickly save all
properties of a chart to a compressed string
variable and recover both data and
appearance later.
1. To serialize / save
all properties to a string variable:
super2d3dGraph1.Settings().GetSettings(discardData
as Boolean)
This will return all
properties in a compressed string value.
Then you can store the returned string
data into a file or database. The
parameter discardData allows you to
include or exclude current values of
chart (replace "super2d3dGraph1" with
your chart object name).
2. To deserialize /
recover all properties from a string
variable:
super2d3dGraph1.Settings().Apply(data as
String, discardData as Boolean)
Pass previous
collected string data to "data"
parameter and specify if you want to
discard any data included in the string
data or not (discardData parameter).
Steps to build sample:
1. Create a new Windows
application project (C#) and name it
WindowsApplication1.
2. Add Super 2d/3d Graph
Library to the toolbox pallete and drag it
to Form1
3. Add three buttons
and rename them to btSaveSettings,
btRandomChart and btRecoverSettings.
3. Copy and paste de
following code:
Form Code
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
Super2d3dGraphLibrary;
namespace
WindowsApplication1
{
public
partial
class
Form1 :
Form
{
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(object
sender,
EventArgs
e)
{
// Sample chart data
SeriesFactory
sf=
new
SeriesFactory();
sf.AddValue(372);
sf.AddValue(293);
sf.AddValue(444);
sf.AddValue(635);
// Sample chart appearance and style
super2d3dGraph1.AutoRefresh =
false;
super2d3dGraph1.Style =
STYLE2D3D.STYLE2D_PIE;
super2d3dGraph1.SeriesLegend =
new
string[]
{"Sample
data"};
super2d3dGraph1.ItemsLegend =
new
String[]
{
"Product 1",
"Product 2",
"Product 3",
"Product 4"
};
super2d3dGraph1.Title =
"Monthly sells";
super2d3dGraph1.TitleColor =
Color.Green;
super2d3dGraph1.TitleFont =
new
Font("Arial",
20);
super2d3dGraph1.BackStyle =
STYLEBACKGROUND.STYLEBACKGROUND_SOLID;
super2d3dGraph1.BorderColor =
Color.White;
super2d3dGraph1.ShowDataTable =
true;
super2d3dGraph1.DataTableBackColor =
Color.GhostWhite;
super2d3dGraph1.DataTableColor =
Color.DarkCyan;
super2d3dGraph1.DataTableFont =
new
Font("Arial",
13);
super2d3dGraph1.DataTableText =
"Sell data";
super2d3dGraph1.ShowItemsLegend =
true;
super2d3dGraph1.BackColor =
Color.White;
super2d3dGraph1.ShowLegend =
true;
super2d3dGraph1.LegendFont =
new
Font("Arial",
10);
super2d3dGraph1.ShowValues =
true;
super2d3dGraph1.ValuesFont =
new
Font("Arial",
10);
super2d3dGraph1.ValuesLocationStyle =
STYLECAPTIONLOCATION.STYLECAPTIONLOCATION_INSIDE;
super2d3dGraph1.ShowXAxis =
false;
// Assign data and paint the chart
sf.ApplyTo(super2d3dGraph1);
super2d3dGraph1.RefreshChart();
}
String _settings;
// will store data and look&feel settings
private
void
btSaveSettings_Click(object
sender,
EventArgs
e)
{
// collect current settings and put them
into a string variable
_settings = super2d3dGraph1.Settings().GetSettings(false);
MessageBox.Show("Current
data and settings saved to string variable.");
}
private
void
btRecoverSettings_Click(object
sender,
EventArgs
e)
{
// decode string variable and apply settings
tu current chart
super2d3dGraph1.Settings().Apply(_settings,
false);
MessageBox.Show("Data
and settings recovered from string
variable.");
}
private
void
btRandomChart_Click(object
sender,
EventArgs
e)
{
// clear current chart and draw a new random
sample chart
super2d3dGraph1.SampleChart();
}
}
}
Result:

|