Example #1
0
        public override void Draw(CurveChartPlotter chart)
        {
            var  ps   = chart.TryFindResource("CardiogramDefaultPath") as Style;
            Path path = new Path();

            path.Style = ps;

            if (this.Color != null)
            {
                path.Stroke = this.Color;
            }

            PolyLineSegment pls = new PolyLineSegment();

            foreach (var item in this.Source)
            {
                // Todo :增加线
                Point ptem = new Point(chart.GetX(item.X), chart.GetY(item.Y));
                pls.Points.Add(ptem);
            }

            PathFigure pf = new PathFigure();

            pf.StartPoint = pls.Points.FirstOrDefault();
            pf.Segments.Add(pls);
            PathGeometry pg = new PathGeometry(new List <PathFigure>()
            {
                pf
            });

            path.Data = pg;
            chart.PathCanvas.Children.Add(path);


            this.Elements.Clear();
            this.Elements.Add(path);
        }
Example #2
0
        public override void Draw(CurveChartPlotter chart)
        {
            List <ShapePointMarker> es = new List <ShapePointMarker>();

            var ps = chart.FindResource("DefaultCurvePath") as Style;
            var ms = chart.FindResource("DefaultMarker") as Style;

            var ts = chart.FindResource("XCenterLable") as Style;
            var d  = chart.FindResource("dashCapline") as Style;

            Path path = new Path();

            path.Style  = ps;
            path.Stroke = this.Color;
            PolyLineSegment pls = new PolyLineSegment();

            List <Point> vs = new List <Point>();

            double minSpace = (chart.MaxValueX - chart.MinValueX) / chart.AutoXAxisCount;

            double param = 5;

            this.Elements.Clear();

            foreach (var item in this.Source)
            {
                // Todo :增加线
                Point ptem = new Point(chart.GetX(item.X), chart.GetY(item.Y));


                if (this.Marker != null && this.Marker.Visibility == Visibility.Visible)
                {
                    ShapePointMarker m = Activator.CreateInstance(this.Marker.GetType()) as ShapePointMarker;
                    m.ScreenPoint = ptem;
                    m.Fill        = this.Marker.Fill;
                    m.Stroke      = this.Marker.Stroke;
                    m.Text        = Math.Round(item.Y, 1).ToString();
                    m.Style       = ms;

                    // Todo :如果周边有小于5的值不显示文本
                    var f = es.Find(k => Math.Abs(k.ScreenPoint.X - ptem.X) < _markTextVisbleLeight && Math.Abs(k.ScreenPoint.Y - ptem.Y) < _markTextVisbleLeight);

                    if (f != null && !string.IsNullOrEmpty(f.Text))
                    {
                        m.Text = string.Empty;
                    }


                    es.Add(m);
                }

                pls.Points.Add(ptem);

                // Todo :增加虚线

                // Todo :存在在范围之内的不添加坐标
                if (vs.Exists(k => Math.Abs(k.X - item.X) < minSpace))
                {
                    continue;
                }

                Line l = new Line();
                l.X1     = 0;
                l.X2     = 0;
                l.Y1     = 0;
                l.Y2     = param;
                l.Stroke = chart.Foreground;
                Canvas.SetLeft(l, chart.GetX(item.X));
                chart.BottomCanvas.Children.Add(l);

                this.Elements.Add(l);

                Label t = new Label();
                t.Content  = item.Text;
                t.Style    = ts;
                t.FontSize = chart.FontSize - 3;
                Canvas.SetLeft(t, chart.GetX(item.X) - t.Width / 2);
                Canvas.SetTop(t, 2 * param - t.Height / 2);
                chart.BottomCanvas.Children.Add(t);

                this.Elements.Add(t);

                // Todo :增加虚线
                Line lx = new Line();
                lx.X1              = 0;
                lx.X2              = 0;
                lx.Y1              = chart.ParallelCanvas.ActualHeight - chart.GetY(item.Y);
                lx.Y2              = 0;
                lx.Style           = d;
                lx.Stroke          = chart.Foreground;
                lx.StrokeThickness = 0.5;
                Canvas.SetLeft(lx, chart.GetX(item.X));
                Canvas.SetBottom(lx, 0);

                if (lx.Y1 > lx.Y2)
                {
                    chart.ParallelCanvas.Children.Add(lx);

                    this.Elements.Add(lx);
                }

                vs.Add(item.ToPoint());
            }

            PathFigure pf = new PathFigure();

            pf.StartPoint = pls.Points.FirstOrDefault();
            pf.Segments.Add(pls);
            PathGeometry pg = new PathGeometry(new List <PathFigure>()
            {
                pf
            });

            path.Data = pg;
            chart.PathCanvas.Children.Add(path);


            this.Elements.Add(path);

            // Todo :绘制Marker
            foreach (var item in es)
            {
                chart.ParallelBottomCanvas.Children.Add(item);

                this.Elements.Add(item);
            }
        }