Glossary Item Box
The .netCHARTING data model consists of elements which collectively become a series which can be added to a SeriesCollection.
Data Class |
Description |
---|---|
Element |
Represents an element on the chart and facilitates the following.
|
Series |
Utilizes the ElementCollection class to hold a set of elements and facilitates the following.
|
SeriesCollection |
Contains a collection of series and facilitates the following.
|
ElementCollection | Used by the Series class to hold a collection of elements. |
The following example creates a SeriesCollection containing one Series which contains a single Element using the following steps.
[C#] Element e = new Element(); // Instantiate the element e.Name = "Element 1"; // Name it e.YValue = 10; // Set the y value Series s = new Series(); // Instantiate the series s.Name = "Series 1"; // Name it s.Elements.Add(e); // Add element e to series s. SeriesCollection sc = new SeriesCollection(); // Instantiate a series collection sc.Add(s); // Add series s to the series collection sc. //The sc object now contains data we can chart which we add here. Chart.SeriesCollection.Add(sc);
[Visual Basic] Dim e As New Element() ' Instantiate the element e.Name = "Element 1" ' Name it e.YValue = 10 ' Set the y value Dim s As New Series() ' Instantiate the series s.Name = "Series 1" ' Name it s.Elements.Add(e) ' Add element e to series s. Dim sc As New SeriesCollection() ' Instantiate a series collection sc.Add(s) ' Add series s to the series collection sc. 'The sc object now contains data we can chart which we add here. Chart.SeriesCollection.Add(sc)
.netCHARTING provides many shortcuts which can make adding data easier. The previous example can also be achieved using the following shortcuts.
[C#] Element e = new Element(); e.Name = "Element 1"; e.YValue = 10; Chart.Series.Add(e); Chart.SeriesCollection.Add(); // Not passing parameters will add the contents of Chart.Series to the chart.
[Visual Basic] Dim e As New Element() e.Name = "Element 1" e.YValue = 10 Chart.Series.Add(e) Chart.SeriesCollection.Add() ' Not passing parameters will add the contents of Chart.Series to the chart.
[C#] Chart.Series.Element.YValue = 10; Chart.Series.Element.Name = "Element 1"; Chart.Series.Elements.Add(); Chart.SeriesCollection.Add();
[Visual Basic] Chart.Series.Element.YValue = 10 Chart.Series.Element.Name = "Element 1" Chart.Series.Elements.Add() Chart.SeriesCollection.Add()
Using all the shortcuts allows us to reduce the amount of lines necessary to achieve the same result from 8 to 4. The down side is that after the data is added using these shortcuts, it cannot be retrieved for further manipulation.
It is still possible to reduce the code even further using element constructors.
[C#] Chart.Series.Add(new Element("Element1",10)); Chart.SeriesCollection.Add();
[Visual Basic] Chart.Series.Add(New Element("Element1",10)) Chart.SeriesCollection.Add()
Now we took it from 8 lines to 2.
2002 - 2005 Webavail Productions Inc. & Corporate Web Solutions Ltd.. All Rights Reserved.