Example #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // new data source
            DataSource ds = new DataSource("PlainGraph Sample");

            // new record
            DataRecord dr = new DataRecord("DVD");
            dr.Color = Color.SkyBlue;
            dr.LineWeight = 2f;       // line weight

            dr.AddData("2010", 3000);
            dr.AddData("2011", 3500);
            dr.AddData("2012", 5000);

            // add record
            ds.AddData(dr);

            // simple way to create record and add
            ds.AddData("Book", new Dictionary<string, double>(){
                { "2010", 2100 },
                { "2011", 2700 },
                { "2012", 2550 },
            }).LineWeight = 3f;

            graph.DataSource = ds; // update data source
            graph.GraphType = PlainGraphType.Column; // change chart type
        }
Example #2
0
        public DataRecord add_data(string title, Dictionary <int, double> values, Color color)
        {
            var record = new DataRecord {
                Key   = title,
                Color = color,
            };

            foreach (var key in values.Keys)
            {
                var set = new DataEntity()
                {
                    Key   = key.ToString(),
                    Value = values[key],
                    Style = new DataEntityStyle {
                        Color = PlainGraphToolkit.get_random_color(),
                    },
                };
                record.Set.Add(set);
            }

            Records.Add(record);
            return(record);
        }
Example #3
0
        public DataRecord add_data(string title, IQueryable <KeyValuePair <string, int> > values, Color color)
        {
            var record = new DataRecord()
            {
                Key   = title,
                Color = color,
            };

            foreach (var key in values.Select(v => v.Key))
            {
                var set = new DataEntity()
                {
                    Key   = key,
                    Value = values.FirstOrDefault(v => v.Key == key).Value,
                    Style = new DataEntityStyle {
                        Color = PlainGraphToolkit.get_random_color(),
                    },
                };
                record.Set.Add(set);
            }

            Records.Add(record);
            return(record);
        }
Example #4
0
 public DataRecord AddData(string name)
 {
     DataRecord record = new DataRecord(name);
     AddData(record);
     return record;
 }
Example #5
0
 public void AddData(DataRecord record)
 {
     records.Add(record);
 }
Example #6
0
        public DataRecord AddData(string title, Dictionary<int, double> values, Color color)
        {
            DataRecord record = new DataRecord()
            {
                Key = title,
                Color = color,
            };

            foreach (int key in values.Keys)
            {
                DataEntity set = new DataEntity()
                {
                    Key = key.ToString(),
                    Value = values[key],
                    Style = new DataEntityStyle
                    {
                        Color = PlainGraphToolkit.GetRandomColor(),
                    },
                };
                record.Set.Add(set);
            }

            records.Add(record);

            return record;
        }
Example #7
0
        public DataRecord AddData(string title, IQueryable<KeyValuePair<string, int>> values, Color color)
        {
            DataRecord record = new DataRecord()
            {
                Key = title,
                Color = color,
            };

            foreach (string key in values.Select(v => v.Key))
            {
                DataEntity set = new DataEntity()
                {
                    Key = key,
                    Value = values.FirstOrDefault(v => v.Key == key).Value,
                    Style = new DataEntityStyle
                    {
                        Color = PlainGraphToolkit.GetRandomColor(),
                    },
                };
                record.Set.Add(set);
            }

            records.Add(record);

            return record;
        }
Example #8
0
 public void AddData(DataRecord record)
 {
     records.Add(record);
 }
Example #9
0
        protected virtual void DrawPieString(Graphics g, Rectangle pieBounds,
			DataRecord record, DataEntity entity, float startAngle, float endAngle)
        {
            if (IsShowEntityName)
            {
                float w = pieBounds.Width / 3.5f;
                float h = pieBounds.Height / 3.5f;

                // angle -> radian
                float radian = (float)((startAngle + endAngle / 2) * Math.PI / 180f);
                double x = w * Math.Cos(radian);
                double y = h * Math.Sin(radian);

                if (x != double.NaN && y != double.NaN)
                {
                    string str = entity.Key.ToString(); //string.Format("{0}%", Math.Round(endAngle / 360f * 100f));
                    SizeF strSize = g.MeasureString(str, Font);

                    g.DrawString(str,
                        Font, Brushes.Black, pieBounds.Left + pieBounds.Width / 2 + (int)x - strSize.Width / 2,
                        pieBounds.Top + pieBounds.Height / 2 + (int)y - strSize.Height / 2);
                }
            }
        }
Example #10
0
        protected virtual void DrawEntityPie(Graphics g, Rectangle pieBounds,
			DataRecord record, DataEntity entity, float startAngle, float endAngle)
        {
            if (pieBounds.Width <= 0 || pieBounds.Height <= 0) return;

            Color color = entity.Style.Color;

            using (Brush b = new SolidBrush(color))
            {
                g.FillPie(b, pieBounds, startAngle, endAngle);
            }

            DrawPieString(g, pieBounds, record, entity, startAngle, endAngle);
        }
Example #11
0
        protected override void DrawEntityPie(Graphics g, Rectangle pieBounds,
			DataRecord record, DataEntity entity, float startAngle, float endAngle)
        {
            if (pieBounds.Width <= 0 || pieBounds.Height <= 0) return;

            //if (record.Set.IndexOf(entity) != 4) return;

            float sa = startAngle + 2f;
            float ea = endAngle - 2f;

            Color color = entity.Style.Color;

            int w = (int)(pieBounds.Width/2f);
            int h = (int)(pieBounds.Height/2f);

            PointF origin = new PointF(pieBounds.Left + w, pieBounds.Top + h);

            RectangleF originRect = new RectangleF(origin.X - 5, origin.Y - 5, 10, 10);
            PointF pto = PointAtArc(origin, originRect, sa + ea / 2);

            RectangleF halfRect = new RectangleF(origin .X - 5, origin.Y - 5, 10, 10);
            PointF pt1 = PointAtArc(pto, halfRect, sa);
            PointF pt2 = PointAtArc(pto, halfRect, sa + ea);

            //using (GraphicsPath gp = new GraphicsPath( FillMode.Winding))
            //{
            //  gp.AddLine(x1, y1, origial.X, origial.Y);
            //  gp.AddLine(origial.X, origial.Y, origial.X, origial.Y + 20);
            //  Rectangle rect = pieBounds;
            //  rect.Offset(0, 20);
            //  gp.AddArc(rect, sa + ea, -ea);

            //  gp.CloseAllFigures();

            //  using (Brush b = new SolidBrush(color))
            //  {
            //    //g.FillPath(b, gp);
            //  }
            //}

            //using (GraphicsPath gp = new GraphicsPath())
            //{
            //  gp.AddArc(pieBounds, sa, ea);
            //  gp.AddLine(origial.X, origial.Y, x1, y1);
            //  //g.DrawLine(Pens.Black, origial.X + x2, origial.Y + y2+20, origial.X, origial.Y);
            //  using (Brush b = new SolidBrush(ControlPaint.Light(color)))
            //  {
            //    //g.FillPath(b, gp);
            //  }
            //}

            float fixedAngle = FixedAngle(sa - 0.1f, halfRect);
            float fixedEndAngle = FixedAngle((sa + ea) - 0.1f, halfRect);

            float a2 = fixedEndAngle - fixedAngle;
            if (a2 < 0) a2 += 360;
            Debug.WriteLine("a2=" + a2);

            g.DrawLine(Pens.Black, pto.X, pto.Y, pt1.X, pt1.Y);
            g.DrawArc(Pens.Black, pieBounds, fixedAngle, a2);
            g.DrawLine(Pens.Black, pt2.X, pt2.Y, pto.X, pto.Y);

            Rectangle rect2 = pieBounds;
            rect2.Offset(0, 20);
            //g.DrawLine(Pens.Blue, origin.X, origin.Y, pt1.X, pt1.Y + 20);
            //g.DrawArc(Pens.Blue, rect2, fixedAngle, a2);
            //g.DrawLine(Pens.Blue, pt2.X, pt2.Y + 20, origin.X, origin.Y);

            DrawPieString(g, pieBounds, record, entity, sa, ea);
        }
Example #12
0
        protected override void DrawPoint(Graphics g, DataEntity entity, Point p, DataRecord record)
        {
            if (entity.Style == null || entity.Style.EndCap == LineCap.Flat)
            {
                int size = (int)(record.LineWeight * 0.75f * PointSize);
                if (size < 5) size = 5;

                using (SolidBrush sb = new SolidBrush(record.Color))
                {
                    g.FillEllipse(sb, p.X - size / 2, p.Y - size / 2, size, size);
                }
            }
        }
Example #13
0
 protected virtual void DrawPoint(Graphics g, DataEntity entity, Point p, DataRecord record)
 {
 }
Example #14
0
        protected override void DrawEntityPie(Graphics g, Rectangle pieBounds,
			DataRecord record, DataEntity entity, float startAngle, float endAngle)
        {
            if (pieBounds.Width <= 0 || pieBounds.Height <= 0) return;

            Color color = entity.Style.Color;

            float w = pieBounds.Width * 1.2f;
            float h = pieBounds.Height * 1.2f;

            float radian = (float)((startAngle + endAngle / 2) * Math.PI / 180f);
            double x = w * Math.Cos(radian);
            double y = h * Math.Sin(radian);

            //if (record.Set.IndexOf(entity) == 3)
            //{
            //  //pieBounds.Inflate(-30, -30);
            //  //pieBounds = new Rectangle((int)x-pieBounds.Width/2, (int)y-pieBounds.Height/2, pieBounds.Width, pieBounds.Height);
            //}
            //else
                pieBounds.Inflate(-20, -20);

            using (Brush b = new SolidBrush(color))
            {
                g.FillPie(b, pieBounds, startAngle, endAngle);
            }

            DrawPieString(g, pieBounds, record, entity, startAngle, endAngle);
        }
Example #15
0
 public void add_data(DataRecord record)
 {
     Records.Add(record);
 }