コード例 #1
0
        // Make pie slices.
        private void MakeCircleChart(Point3D center, double r1, double r2,
                                     double height, double[] values, Brush[] brushes, int numPieces, Model3DGroup group)
        {
            // Calculate percentages.
            double total     = values.Sum();
            int    numValues = values.Length;

            double[] percents = new double[numValues];
            for (int i = 0; i < numValues; i++)
            {
                percents[i] = values[i] / total;
            }

            // Draw slices.
            double minTheta = 0;

            for (int i = 0; i < numValues; i++)
            {
                double         maxTheta    = minTheta + 360.0 * percents[i];
                MeshGeometry3D mesh        = new MeshGeometry3D();
                int            slicePieces = (int)(numPieces * percents[i]);
                if (slicePieces < 2)
                {
                    slicePieces = 2;
                }
                mesh.AddCircleSlice(center, height, minTheta, maxTheta,
                                    r1, r2, slicePieces);
                group.Children.Add(mesh.MakeModel(brushes[i]));

                minTheta = maxTheta;
            }
        }