Chart3D for WPF and Silverlight | ComponentOne
Chart3D for WPF and Silverlight Overview / Getting Started / Quick Start: Chart3D for WPF and Silverlight / Step 2: Adding Data
In This Topic
    Step 2: Adding Data
    In This Topic

    Chart3D for WPF and Silverlight supports data values defined as a two-dimensional array of z-values where the first index corresponds to X and the second index corresponds to Y. One of the most common uses of a Chart3D is plotting 3D functions. Let's plot a function defined as the following:

    z(x,y) = x*x - y*y;

    in the range

    -1 <= x <= 1

    -1 <= y <= 1

     To do this, follow these steps:

    1. Select View | Code in your project.
    2. Add the following statement at the top of the page: 
    C# - WPF
    Copy Code
    using C1.WPF.Chart3D;
    

     

    C# - Silverlight
    Copy Code
    using C1.Silverlight.Chart3D
    
    1. Add the following code to define the data:
    C#
    Copy Code
    public MainWindow()
            {
                InitializeComponent();
                c1Chart3D1.Children.Clear();
     
                // create 2D array 10x10
                int xlen = 10, ylen = 10;
                var zdata = new double[xlen, ylen];
                double stepx = 2.0 / (xlen - 1);
                double stepy = 2.0 / (ylen - 1);
                // calculate function for all points in the range
                for (int ix = 0; ix < xlen; ix++)
                    for (int iy = 0; iy < ylen; iy++)
                    {
                        double x = -1.0 + ix * stepx; //  -1 <= x <= 1
                        double y = -1.0 + iy * stepy; //  -1 <= x <= 1
                        zdata[ix, iy] = x * x - y * y;
                    }
                // create data series
                var ds = new GridDataSeries();
                ds.Start = new Point(-1, -1); // start for x,y
                ds.Step = new Point(stepx, stepy); // step for x,y
                ds.ZData = zdata; // z-values
                // add series to the chart
                c1Chart3D1.Children.Add(ds);
            }
    

     In the next step you will change the appearance of the chart. 

     

    See Also