.Net Chart Control A powerful component for convenient charting.
More
convenience more functionality in Ver. 3.5 |
|||||||
|
|
Using Themes |
||
| Click here to get sample solution. | ||
Themes in the Manco.Chart are the real building blocks of the chart layout.
Using themes you or your users can create desirable view of the chart during a
few seconds. Theme is an XML document that contains ready to use part of the
chart layout. The root element of this document could be one of the following:
<Charts>, <ComponentLayout> or <Layout>. It could contain any
or all parts of the chart layout (see content of the files are located in the
subfolders of the Art\Themes folder for theme’s examples). There is one
additional attribute that manages theme element loading. This is
"Manco.Chart.LoadMode". You can insert this attribute to any node of theme. It
can have following values:
|
||
|
Let see how it could be used on practice. At the first we should create simple chart desktop application.
Prepare simple XML chart document and put it to the folder near the application executable (bin\Debug or bin\Release). The chart XML could looks like the following: <?xml version="1.0" encoding="utf-8" ?> <Charts> <ComponentLayout> </ComponentLayout> <Chart> <Layout Type="Pie"> </Layout> <Data> <Value Series="Ser1" Category="Cat1" Value="15" /> <Value Series="Ser2" Category="Cat1" Value="19" /> <Value Series="Ser3" Category="Cat1" Value="17" /> </Data> </Chart> </Charts> You see, that this document doesn't contain any decoration elements. So the chart you will see will have only default colors. |
||
Add code to load chart XML document and draw chart to the form’s On Load event
handler. It could looks like the following:
private XmlDocument xmlChart; private void Form1_Load(object sender, System.EventArgs e) { xmlChart = new XmlDocument(); xmlChart.Load(Path.GetDirectoryName(Application.ExecutablePath) + "\\IntroChart.xml"); chartControl.ChartDocument = xmlChart; chartControl.Draw(); } |
||
|
Now we need a code to load theme. Drag and drop OpenFileDialog control to your form. Change its Name to something like that: ofdLoadTheme. Set Filter property to the “Theme (*.xml)|*.xml|All Files (*.*)|*.*” value. Drag and drop Button control somewhere on your form. Change its Text and Name properties if you’d like. Double click on it to add On Click event handler for this button. Add code to load theme from the file: private void cmdLoadTheme_Click(object sender, System.EventArgs e) { ofdLoadTheme.InitialDirectory = Path.Combine(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Art"), "Themes"); if(ofdLoadTheme.ShowDialog() == DialogResult.OK) { // Load theme to the chart document Manco.Chart.Layouts.Layout.LoadTheme(ofdLoadTheme.FileName, xmlChart.DocumentElement); // Regenerate layout and draw chart chartControl.RegenerateLayout(); chartControl.Draw(); } } |
||
| Copy Art folder from the Chart Component .NET installation folder to the folder where your executable is located (bin\Debug or bin\Release). | ||
|
Run your application. You will see the chart with defult colors.
Click button you've added to load theme. You will see standard file dialog with few directories:
Click
here to get sample solution.
These directories contains themes that are provided with Chart Component .NET. Try to load different thems and see result. |
||
| Our another product: .Net Licensing System Back to main page of .Net Chart | ||
|