예제 #1
0
        /// <summary>
        /// Draws the polyline.
        /// </summary>
        /// <param name="canvas">The canvas.</param>
        /// <param name="pointList">The point list.</param>
        private void drawPolyline(Canvas canvas, List <Point> pointList)
        {
            Polyline polyline = new Polyline();

            polyline.StrokeDashArray = ChartControl.GetShapePattern(this.ChartStyle.StrokePattern);
            polyline.Stroke          = this.ChartStyle.Stroke;
            polyline.StrokeThickness = this.ChartStyle.StrokeThickness;

            polyline.Points = new PointCollection(pointList);
            canvas.Children.Add(polyline);
        }
예제 #2
0
        /// <summary>
        /// Draws the impulses.
        /// </summary>
        /// <param name="canvas">The canvas.</param>
        /// <param name="pointList">The point list.</param>
        private void drawImpulses(Canvas canvas, List <Point> pointList)
        {
            Point origin = this.normalizedOriginPoint;

            foreach (Point point in pointList)
            {
                Line impuls = new Line();
                impuls.StrokeDashArray = ChartControl.GetShapePattern(this.ChartStyle.StrokePattern);
                impuls.Stroke          = this.ChartStyle.Stroke;
                impuls.StrokeThickness = this.ChartStyle.StrokeThickness;
                impuls.X1 = point.X;
                impuls.Y1 = origin.Y;
                impuls.X2 = point.X;
                impuls.Y2 = point.Y;
                canvas.Children.Add(impuls);
            }
        }
예제 #3
0
        /// <summary>
        /// Draws the steps.
        /// </summary>
        /// <param name="canvas">The canvas.</param>
        /// <param name="pointList">The point list.</param>
        private void drawSteps(Canvas canvas, List <Point> pointList)
        {
            Polyline stepsPolyline = new Polyline();

            stepsPolyline.StrokeDashArray = ChartControl.GetShapePattern(this.ChartStyle.StrokePattern);
            stepsPolyline.Stroke          = this.ChartStyle.Stroke;
            stepsPolyline.StrokeThickness = this.ChartStyle.StrokeThickness;

            double previousYValue = double.NaN;

            foreach (Point point in pointList)
            {
                if (!double.IsNaN(previousYValue))
                {
                    Point stepPoint = new Point(point.X, (double)previousYValue);
                    stepsPolyline.Points.Add(stepPoint);
                }
                stepsPolyline.Points.Add(point);
                previousYValue = point.Y;
            }
            canvas.Children.Add(stepsPolyline);
        }
예제 #4
0
        /// <summary>
        /// Sets the legend.
        /// </summary>
        public void SetLegend()
        {
            int seriesCount = this.chartControl.DataCollection.Count;

            if (!chartControl.IsLegend || seriesCount == 0)
            {
                return;
            }

            string[] seriesNames = getSeriesNames();

            double    legendWidth  = 0;
            double    legendHeight = 0;
            TextBlock textBlock    = new TextBlock();
            Size      size         = new Size();

            for (int i = 0; i < seriesNames.Length; i++)
            {
                textBlock.Text = seriesNames[i];
                textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                size = textBlock.DesiredSize;
                if (legendWidth < size.Width)
                {
                    legendWidth = size.Width;
                }
            }
            legendWidth += 50;
            legendHeight = 17 * seriesCount;

            double    sx         = 6;
            double    sy         = 0;
            double    textHeight = size.Height;
            double    lineLength = 34;
            Rectangle legendRect = new Rectangle();

            legendRect.Stroke = Brushes.Black;
            legendRect.Fill   = Brushes.White;
            legendRect.Width  = legendWidth;
            legendRect.Height = legendHeight;

            if (this.chartControl.IsLegendBorder)
            {
                this.chartControl.legendCanvas.Children.Add(legendRect);
            }
            Canvas.SetZIndex(this.chartControl.legendCanvas, 10);

            int n = 1;

            foreach (DataSeries dataSeries in this.chartControl.DataCollection)
            {
                double xSymbol = sx + lineLength / 2;
                double xText   = 2 * sx + lineLength;
                double yText   = n * sy + (2 * n - 1) * textHeight / 2;
                Line   line    = new Line();
                line.Stroke          = dataSeries.ChartStyle.Stroke;
                line.StrokeThickness = dataSeries.ChartStyle.StrokeThickness;
                line.StrokeDashArray = ChartControl.GetShapePattern(dataSeries.ChartStyle.StrokePattern);
                line.X1 = sx;
                line.Y1 = yText;
                line.X2 = sx + lineLength;
                line.Y2 = yText;
                if (dataSeries.ChartStyle.DrawType != DrawType.None)
                {
                    this.chartControl.legendCanvas.Children.Add(line);
                }
                Point point = new Point(0.5 * (line.X2 - line.X1 + dataSeries.ChartStyle.SymbolSize) + 1, line.Y1);

                SymbolType symbol = dataSeries.ChartStyle.SymbolType;
                if (symbol == SymbolType.Bar)
                {
                    symbol = SymbolType.Box;
                }

                dataSeries.AddSymbol(symbol, this.chartControl.legendCanvas, point);

                textBlock      = new TextBlock();
                textBlock.Text = seriesNames[n - 1];
                this.chartControl.legendCanvas.Children.Add(textBlock);
                Canvas.SetTop(textBlock, yText - size.Height / 2);
                Canvas.SetLeft(textBlock, xText);
                n++;
            }
            this.chartControl.legendCanvas.Width  = legendRect.Width;
            this.chartControl.legendCanvas.Height = legendRect.Height;

            setLegendPosition(this.chartControl.chartCanvas, legendRect);
        }