Example #1
0
        private void _drawLines(int mod, int rem)
        {
            bool animate = (this.AnimationDuration > 0);

            double marginLeft = MarginLeft, marginTop = MarginTop;
            double marginRight = MarginRight, marginBottom = MarginBottom;

            double      gridWidth = (ChartCanvas.Width - marginLeft - marginRight);
            double      gridHeight = (ChartCanvas.Height - marginTop - marginBottom);
            LookAndFeel lf = CurrentLookAndFeel;
            string      lineDotXAML = lf.GetLineDotXAML(),
                        pathXAML = lf.GetLinePathXAML();
            Path             pathElem, dotElement;
            List <UIElement> dataElems        = null;
            MatrixTransform  defaultTransform = null;

            if (animate)
            {
                dataElems = DataElements;
            }

            bool       isStacked = (Type == ChartType.AREA_STACKED);
            ChartModel model     = Model;

            string[] groupLabels = model.GroupLabels;
            int      groupCount  = groupLabels.Length;

            string[] seriesLabels = model.SeriesLabels;
            int      seriesCount  = seriesLabels.Length;

            Color[] seriesColors = model.SeriesColors;
            double[,] yValues = model.YValues;

            double minValue = model.MinYValue, maxValue = model.MaxYValue;

            int yValueCount = yValues.GetUpperBound(0) + 1;

            string gradientXAML = lf.GetElementGradientXAML();
            double barWidth = gridWidth / Math.Max(yValueCount, groupCount);
            double dx, dy;

            for (int i = 0; i < seriesCount; ++i)
            {
                // for combo charts we draw a bar every once in a mod.
                if ((mod > 1) && (i % mod) != rem)
                {
                    continue;
                }

                dx = marginLeft + barWidth / 2;

                StringBuilder sb = new StringBuilder();

                for (int j = 0; j < yValueCount; ++j)
                {
                    dy = gridHeight + marginTop - gridHeight * (yValues[j, i] - minValue) / (maxValue - minValue);

                    if (j == 0)
                    {
                        sb.Append("M").Append(dx).Append(",").Append(dy);
                    }
                    else
                    {
                        sb.Append("L").Append(dx).Append(",").Append(dy);
                    }

                    dotElement = XamlReader.Load(lineDotXAML) as Path;
                    EllipseGeometry rectG = dotElement.Data as EllipseGeometry;
                    rectG.Center = new Point(dx, dy);

                    if (gradientXAML != null)
                    {
                        SetGradientOnElement(dotElement, gradientXAML, seriesColors[i], 0xe5);
                    }
                    else
                    {
                        SetFillOnElement(dotElement, seriesColors[i]);
                    }

                    dotElement.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

                    if (animate)
                    {
                        dataElems.Add(dotElement);
                        defaultTransform = new MatrixTransform();
                        Matrix m = new Matrix();
                        m.M11 = 0.0;
                        defaultTransform.Matrix = m;
                        dotElement.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                    }
                    ChartCanvas.Children.Add(dotElement);

                    dx += barWidth;
                }

                pathElem = CreatePathFromXAMLAndData(pathXAML, sb);
                // There is no fill for lines
                pathElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i]));

                SetExpandosOnElement(pathElem, -1, i, new Point());
                if (DisplayToolTip)
                {
                    pathElem.MouseMove  += new MouseEventHandler(ShowToolTip);
                    pathElem.MouseLeave += new MouseEventHandler(HideToolTip);
                }
                pathElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked);

                if (animate)
                {
                    dataElems.Add(pathElem);
                    defaultTransform = new MatrixTransform();
                    Matrix m = new Matrix();
                    m.M11 = 0.0;
                    defaultTransform.Matrix = m;
                    pathElem.SetValue(UIElement.RenderTransformProperty, defaultTransform);
                }
                ChartCanvas.Children.Add(pathElem);
            }
        }