public DataEntity add_data(string name, double value, Color color) { var entity = new DataEntity { Key = name, Value = value, }; if (color != Color.Empty) { entity.Style = new DataEntityStyle { Color = color, }; } Set.Add(entity); return(entity); }
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); }
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); }
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; }
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; }
public DataEntity AddData(string name, double value, Color color) { DataEntity entity = new DataEntity { Key = name, Value = value, }; if (color != Color.Empty) { entity.Style = new DataEntityStyle { Color = color, }; } set.Add(entity); return entity; }
private float GetEntityAngle(DataEntity entity) { return (float)( entity.Value * 360f / recordInfo.recordTotal[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); } } }
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); }
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); }
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); } } }
protected virtual void DrawPoint(Graphics g, DataEntity entity, Point p, DataRecord record) { }
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); }
protected void DrawValue(Graphics g, int x, int y, DataEntity entity) { using (Brush b = entity.Style == null ? Brushes.Black : new SolidBrush(entity.Style.Color)) { g.DrawString(entity.Value.ToString(), Font, b, x, y); } }