Chart initialization

In our application, which we will call the workbench for short, we are dealing with two charts. The first chart is three-dimensional, the second is two-dimensional. Each one reflects the same data albeit from a different perspective. In our chart initialization function, we will initialize both charts at the same time.

  • chartPSO is the name of our two-dimensional Microsoft Chart Control chart
  • nChartControl2 is the name of our three-dimensional Nevron chart

Why not use the same control for both visualizations? That certainly could have been the case, but this way you, the reader, get exposure to two different types of control and can decide which you prefer.

The first thing that we will do is to create a random variable called _MarkerStyle. Each particle will have a different marker style in the two-dimensional plot, and we will use this random variable to control the correct creation of the style like this:

FastRandom _MarkerStyle = new FastRandom();

Next on our list of things to do is to clear the series data from both controls, just in case there is data left over. We do so with the following two lines of code. Remember, chartPSO is our two-dimensional chart and, nChartControl2 is our three-dimensional chart control:

chartPSO?.Series?.Clear();
nChartControl2?.Charts?[0]?.Series?.Clear();

To get the best visualization from our three-dimensional control, we need to ensure that it fits the entire chart area. We do that by setting the bounds mode like this:

nChartControl2.Charts[0].BoundsMode = BoundsMode.Stretch;

Now, we need to make sure that each particle in the swarm has an area of representation in both charts. We do that by iterating through the swarm size and setting each variable correctly. We start by adding the two-dimensional chart configuration first:

for (int i = 0; i < maxSwarm; i++)
{
chartPSO?.Series?.Add("Swarm(" + i + ")");
chartPSO.Series[i].ChartType = SeriesChartType.Spline;
chartPSO.Series[i].MarkerStyle = (MarkerStyle)_MarkerStyle.Next(1, 10);
chartPSO.Series[i].MarkerSize = 10;

And then the three-dimensional chart configuration, like this:

for (int i = 0; i < maxSwarm; i++)
{
NLineSeries m_Line1 = (NLineSeries)nChartControl2.Charts[0].Series.Add(SeriesType.Line);
m_Line1.MultiLineMode = MultiLineMode.Series;
m_Line1.LineSegmentShape = LineSegmentShape.Tape;
m_Line1.DataLabelStyle.Visible = false;
m_Line1.DepthPercent = 50;
m_Line1.Name = "Swarm(" + i + ")";

Next, let's set the final variables of the two-dimensional chart as follows:

chartPSO?.Series?.Add("GlobalPosition");
chartPSO.Series[maxSwarm].ChartType = SeriesChartType.Point;
chartPSO.Series[maxSwarm].MarkerStyle = MarkerStyle.Diamond;
chartPSO.Series[maxSwarm].Color = Color.Black;
chartPSO.Series[maxSwarm].MarkerSize = 20;

And finally, to give our three-dimensional chart the most flexibility for use, we need to add the following toolbars:

nChartControl2.Controller?.Tools?.Add(new NTrackballTool());
nChartControl2.Controller?.Tools?.Add(new NZoomTool());
nChartControl2.Controller?.Tools?.Add(new NOffsetTool());
nChartControl2.Controller?.Tools?.Add(new NAxisScrollTool());
NPanelSelectorTool selector = new NPanelSelectorTool();
selector.Focus = true;
nChartControl2.Controller.Tools.Add(selector);
nChartControl2.Controller.Tools.Add(new NDataZoomTool());
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset