private void AddChart()
        {
            chartCanvas.Children.Clear();
            cs                 = new ChartStyle();
            cs.ChartCanvas     = this.chartCanvas;
            cs.GridlinePattern = ChartStyle.GridlinePatternEnum.Solid;
            cs.Elevation       = 30;
            cs.Azimuth         = -37;
            cs.Title           = "No Title";
            cs.IsColorBar      = true;
            cs.AddChartStyle();

            ds           = new DataSeriesSurface();
            ds.LineColor = Brushes.Black;
            Utility.Peak3D(cs, ds);
            dsc = new DrawSurfaceChart();
            dsc.SurfaceChartType           = DrawSurfaceChart.SurfaceChartTypeEnum.Surface;
            dsc.IsColormap                 = true;
            dsc.IsHiddenLine               = true;
            dsc.IsInterp                   = true;
            dsc.NumberInterp               = 3;
            dsc.Colormap.ColormapBrushType = ColormapBrush.ColormapBrushEnum.Jet;
            dsc.AddSurfaceChart(cs, ds);
        }
        public void AddChartStyle2D(DrawSurfaceChart dsc)
        {
            colorbarWidth = ChartCanvas.Width / 7;
            ChartCanvas.Children.Clear();
            ChartCanvas.Children.Add(chart2dBorder);
            Point     pt = new Point();
            Line      tick = new Line();
            double    offset = 0;
            double    dx, dy;
            TextBlock tb = new TextBlock();

            //  determine right offset:
            tb.Text = Xmax.ToString();
            tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            Size size = tb.DesiredSize;

            rightOffset = size.Width / 2 + 2;

            // Determine left offset:
            for (dy = Ymin; dy <= Ymax; dy += YTick)
            {
                pt               = NormalizePoint(new Point(Xmin, dy));
                tb               = new TextBlock();
                tb.Text          = dy.ToString();
                tb.TextAlignment = TextAlignment.Right;
                tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                size = tb.DesiredSize;
                if (offset < size.Width)
                {
                    offset = size.Width;
                }
            }
            leftOffset = offset + 5 + 30;

            Canvas.SetLeft(chart2dBorder, leftOffset);
            Canvas.SetBottom(chart2dBorder, bottomOffset);
            if (!IsColorBar)
            {
                colorbarWidth = 0;
            }
            chart2dCanvas.Width  = ChartCanvas.Width - leftOffset - rightOffset - colorbarWidth;
            chart2dCanvas.Height = ChartCanvas.Height - bottomOffset - size.Height / 2;

            // Create vertical gridlines:
            if (IsYGrid == true)
            {
                for (dx = Xmin + XTick; dx < Xmax; dx += XTick)
                {
                    gridline                 = new Line();
                    gridline.Stroke          = GridlineColor;
                    gridline.StrokeThickness = GridlineThickness;
                    gridline.X1              = NormalizePoint(new Point(dx, Ymin)).X;
                    gridline.Y1              = NormalizePoint(new Point(dx, Ymin)).Y;
                    gridline.X2              = NormalizePoint(new Point(dx, Ymax)).X;
                    gridline.Y2              = NormalizePoint(new Point(dx, Ymax)).Y;
                    chart2dCanvas.Children.Add(gridline);
                }
            }

            // Create horizontal gridlines:
            if (IsXGrid == true)
            {
                for (dy = Ymin + YTick; dy < Ymax; dy += YTick)
                {
                    gridline                 = new Line();
                    gridline.Stroke          = GridlineColor;
                    gridline.StrokeThickness = GridlineThickness;
                    gridline.X1              = NormalizePoint(new Point(Xmin, dy)).X;
                    gridline.Y1              = NormalizePoint(new Point(Xmin, dy)).Y;
                    gridline.X2              = NormalizePoint(new Point(Xmax, dy)).X;
                    gridline.Y2              = NormalizePoint(new Point(Xmax, dy)).Y;
                    chart2dCanvas.Children.Add(gridline);
                }
            }

            // Create x-axis tick marks:
            for (dx = Xmin; dx <= Xmax; dx += XTick)
            {
                pt          = NormalizePoint(new Point(dx, Ymin));
                tick        = new Line();
                tick.Stroke = Brushes.Black;
                tick.X1     = pt.X;
                tick.Y1     = pt.Y;
                tick.X2     = pt.X;
                tick.Y2     = pt.Y - 5;
                chart2dCanvas.Children.Add(tick);

                tb      = new TextBlock();
                tb.Text = dx.ToString();
                tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                size = tb.DesiredSize;
                ChartCanvas.Children.Add(tb);
                Canvas.SetLeft(tb, leftOffset + pt.X - size.Width / 2);
                Canvas.SetTop(tb, pt.Y + 2 + size.Height / 2);
            }

            // Create y-axis tick marks:
            for (dy = Ymin; dy <= Ymax; dy += YTick)
            {
                pt          = NormalizePoint(new Point(Xmin, dy));
                tick        = new Line();
                tick.Stroke = Brushes.Black;
                tick.X1     = pt.X;
                tick.Y1     = pt.Y;
                tick.X2     = pt.X + 5;
                tick.Y2     = pt.Y;
                chart2dCanvas.Children.Add(tick);

                tb      = new TextBlock();
                tb.Text = dy.ToString();
                tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                size = tb.DesiredSize;
                ChartCanvas.Children.Add(tb);
                Canvas.SetRight(tb, chart2dCanvas.Width + 10 + colorbarWidth);
                Canvas.SetTop(tb, pt.Y);
            }

            tb            = new TextBlock();
            tb.Text       = XLabel;
            tb.FontFamily = LabelFont;
            tb.FontSize   = LabelFontSize;
            tb.Foreground = LabelColor;
            tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            size = tb.DesiredSize;
            ChartCanvas.Children.Add(tb);
            Canvas.SetBottom(tb, bottomOffset / 10);
            Canvas.SetLeft(tb, leftOffset + chart2dCanvas.Width / 2 - size.Width / 2);

            tb                 = new TextBlock();
            tb.Text            = YLabel;
            tb.FontFamily      = LabelFont;
            tb.FontSize        = LabelFontSize;
            tb.Foreground      = LabelColor;
            tb.RenderTransform = new RotateTransform(-90, 0.5, 0.5);

            tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            size = tb.DesiredSize;
            ChartCanvas.Children.Add(tb);
            Canvas.SetBottom(tb, chart2dCanvas.Height / 2 + size.Width / 3);
            Canvas.SetLeft(tb, leftOffset / 10);
        }