You add a new chart by adding an instance of one of the following classes to the Panels collection of the control:
NCartesianChart
NPieChart
NPolarChart
NRadarChart
NVennChart
For example:
C# |
Copy Code
|
---|---|
NCartesianChart chart = new NCartesianChart();
chartControl.Panels.Add(chart);
|
Visual Basic |
Copy Code
|
---|---|
Dim chart As NCartesianChart = New NCartesianChart() chartControl.Panels.Add(chart) |
By default there is always one Cartesian chart so you can always index the first chart in the Charts collection at startup:
C# |
Copy Code
|
---|---|
NCartesianChart chart = chartControl.Charts[0]; |
Visual Basic |
Copy Code
|
---|---|
Dim chart As NCartesianChart = chartControl.Charts(0) |
After you add the chart to the control you can modify its DisplayOnLegend property, which defines the legend where series will place data (note that individual series may override this property):
C# |
Copy Code
|
---|---|
NChart chart2 = new NCartesianChart();
chartControl.Panels.Add(chart2);
chart2.DisplayOnLegend = chartControl.Legends[0];
|
Visual Basic |
Copy Code
|
---|---|
Dim chart2 As New NCartesianChart chartControl.Panels.Add(chart2) chart2.DisplayOnLegend = chartControl.Legends(0) |
You can associate the one chart with only one legend, but one legend can have many associated charts displaying data on it. The legend mode should be set to Automatic otherwise the data supplied by the chart(s) will be discarded.