[]
        
(Showing Draft Content)

Charting Data from a Mathematical Calculation

Often it may not be convenient to load chart data from a file. For example, if the data is created from within the program using a mathematical calculation, it makes more sense to read it into the chart directly instead of saving it to a file and then reading it again. Not only can this method be quicker, it can also be quite easy to program.

The following example creates a regular grid dataset using a precalculated two-dimensional array and then transfers it to the chart:

To write code in Visual Basic

' Calculate array
Dim Rnd As Random = New Random()
Dim m,n As Integer
Dim z(20,30) As Double
For m = 0 To 30
  For n = 0 To 20
   If m Mod 2 = 0 Then
     Z(n, m) = m * 5 * Rnd.NextDouble() + Math.Sqrt(2 * m * m * n)
   Else
     Z(n, m) = m * -5 * Rnd.NextDouble() + Math.Sqrt(2 * m * n)
   End If
  Next n
Next m
' create dataset and put it to the chart
Dim gridset As Chart3DDataSetGrid
gridset=New Chart3DDataSetGrid( 0, 0, 1, 1, z)
C1Chart3D1.ChartGroups(0).ChartData.Set = gridset

To write code in C#

// Calculate array
Random rnd = new Random();
double[,] z = new  double[21, 31];
for( int m = 0; m<31; m++)
  for( int n = 0; n<21; n++)
 {
  if(m%2==0)
   z[n,m]= m * 5 * rnd.NextDouble() + Math.Sqrt(2 * m * m * n);
  else
   z[n,m]= m * -5 * rnd.NextDouble() + Math.Sqrt(2 * m * n);
 }
// create dataset and put it to the chart
Chart3DDataSetGrid gridset=new Chart3DDataSetGrid(0,0,1,1,z);
C1Chart3D1.ChartGroups[0].ChartData.Set = gridset;

See Also

Displaying 4D Data