public void Remove(DataItem value) { this.List.Remove(value); }
public int IndexOf(DataItem value) { return this.List.IndexOf(value); }
public bool Contains(DataItem value) { return this.List.Contains(value); }
private void DrawBars(Graphics graph) { SolidBrush brsFont = null; Font valFont = null; StringFormat sfFormat = null; try { brsFont = new SolidBrush(this._fontColor); valFont = new Font(this._fontFamily, _labelFontSize); sfFormat = new StringFormat(); sfFormat.Alignment = StringAlignment.Center; int i = 0; PointF[] linePoints = null; if (this._renderMode == BarGraphRenderMode.Lines) { linePoints = new PointF[this.DataPoints.Count]; } int pointIndex = 0; // Draw bars and the value above each bar using (Pen pen = new Pen(this._fontColor, 0.15f)) { using (SolidBrush whiteBrsh = new SolidBrush(Color.FromArgb(128, Color.White))) { foreach (DataItem item in this.DataPoints) { using (SolidBrush barBrush = new SolidBrush(item.ItemColor)) { float itemY = this._yOrigin + this._graphHeight - item.SweepSize; if (this._renderMode == BarGraphRenderMode.Lines) { linePoints[pointIndex++] = new PointF(this._xOrigin + item.StartPos + (this._barWidth / 2), itemY); } else if (this._renderMode == BarGraphRenderMode.Bars) { float ox = this._xOrigin + item.StartPos; float oy = itemY; float ow = this._barWidth; float oh = item.SweepSize; float of = 9.5f; PointF[] pts = new PointF[] { new PointF(ox, oy), new PointF(ox + ow, oy), new PointF(ox + of, oy + of), new PointF(ox + of + ow, oy + of), new PointF(ox, oy + oh), new PointF(ox + of, oy + of + oh), new PointF(ox + of + ow, oy + of + oh) }; graph.FillPolygon(barBrush, new PointF[] { pts[2], pts[3], pts[6], pts[5] }); using (SolidBrush ltBrsh = new SolidBrush(System.Windows.Forms.ControlPaint.Light(item.ItemColor, 0.1f))) graph.FillPolygon(ltBrsh, new PointF[] { pts[0], pts[2], pts[5], pts[4] }); using (SolidBrush drkBrush = new SolidBrush(System.Windows.Forms.ControlPaint.Dark(item.ItemColor, 0.05f))) graph.FillPolygon(drkBrush, new PointF[] { pts[0], pts[1], pts[3], pts[2] }); graph.DrawLine(pen, pts[0], pts[1]); graph.DrawLine(pen, pts[0], pts[2]); graph.DrawLine(pen, pts[1], pts[3]); graph.DrawLine(pen, pts[2], pts[3]); graph.DrawLine(pen, pts[2], pts[5]); graph.DrawLine(pen, pts[0], pts[4]); graph.DrawLine(pen, pts[4], pts[5]); graph.DrawLine(pen, pts[5], pts[6]); graph.DrawLine(pen, pts[3], pts[6]); // Draw data value if (this._displayBarData && (i % this._interval) == 0) { float sectionWidth = (this._barWidth + this._spaceBtwBars); float startX = this._xOrigin + (i * sectionWidth) + (sectionWidth / 2); // This draws the value on center of the bar float startY = itemY - 2f - valFont.Height; // Positioned on top of each bar by 2 pixels RectangleF recVal = new RectangleF(startX - ((sectionWidth * this._interval) / 2), startY, sectionWidth * this._interval, valFont.Height); SizeF sz = graph.MeasureString(item.Value.ToString("#,###.##"), valFont, recVal.Size, sfFormat); //using ( SolidBrush brsh = new SolidBrush( Color.FromArgb( 180, 255, 255, 255 ) ) ) // graph.FillRectangle( brsh, new RectangleF(recVal.X+((recVal.Width-sz.Width)/2),recVal.Y+((recVal.Height-sz.Height)/2),sz.Width+4,sz.Height) ); //graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); for (int box = -1; box <= 1; ++box) { for (int boy = -1; boy <= 1; ++boy) { if (box == 0 && boy == 0) { continue; } RectangleF rco = new RectangleF(recVal.X + box, recVal.Y + boy, recVal.Width, recVal.Height); graph.DrawString(item.Value.ToString("#,###.##"), valFont, whiteBrsh, rco, sfFormat); } } graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); } } i++; } } if (this._renderMode == BarGraphRenderMode.Lines) { if (linePoints.Length >= 2) { using (Pen linePen = new Pen(Color.FromArgb(220, Color.Red), 2.5f)) graph.DrawCurve(linePen, linePoints, 0.5f); } using (Pen linePen = new Pen(Color.FromArgb(40, this._fontColor), 0.8f)) { for (int j = 0; j < linePoints.Length; ++j) { graph.DrawLine(linePen, linePoints[j], new PointF(linePoints[j].X, this._yOrigin + this._graphHeight)); DataItem item = this.DataPoints[j]; float itemY = this._yOrigin + this._graphHeight - item.SweepSize; // Draw data value if (this._displayBarData && (j % this._interval) == 0) { graph.FillEllipse(brsFont, new RectangleF(linePoints[j].X - 2.0f, linePoints[j].Y - 2.0f, 4.0f, 4.0f)); float sectionWidth = (this._barWidth + this._spaceBtwBars); float startX = this._xOrigin + (j * sectionWidth) + (sectionWidth / 2); // This draws the value on center of the bar float startY = itemY - 2f - valFont.Height; // Positioned on top of each bar by 2 pixels RectangleF recVal = new RectangleF(startX - ((sectionWidth * this._interval) / 2), startY, sectionWidth * this._interval, valFont.Height); SizeF sz = graph.MeasureString(item.Value.ToString("#,###.##"), valFont, recVal.Size, sfFormat); //using ( SolidBrush brsh = new SolidBrush( Color.FromArgb( 48, 255, 255, 255 ) ) ) // graph.FillRectangle( brsh, new RectangleF(recVal.X+((recVal.Width-sz.Width)/2),recVal.Y+((recVal.Height-sz.Height)/2),sz.Width+4,sz.Height) ); for (int box = -1; box <= 1; ++box) { for (int boy = -1; boy <= 1; ++boy) { if (box == 0 && boy == 0) { continue; } RectangleF rco = new RectangleF(recVal.X + box, recVal.Y + boy, recVal.Width, recVal.Height); graph.DrawString(item.Value.ToString("#,###.##"), valFont, whiteBrsh, rco, sfFormat); } } graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); } } } } } } } finally { if (brsFont != null) { brsFont.Dispose(); } if (valFont != null) { valFont.Dispose(); } if (sfFormat != null) { sfFormat.Dispose(); } } }
public int Add(DataItem value) { return this.List.Add(value); }
public bool Contains(DataItem value) { return(this.List.Contains(value)); }
public int IndexOf(DataItem value) { return(this.List.IndexOf(value)); }
public int Add(DataItem value) { return(this.List.Add(value)); }
//********************************************************************* // // This method returns a bitmap to the calling function. This is the method // that actually draws the pie chart and the legend with it. // //********************************************************************* public override Bitmap Draw() { int perimeter = _perimeter; Rectangle pieRect = new Rectangle(0, 0, perimeter, perimeter - 1); Bitmap bmp = new Bitmap(perimeter + _legendWidth, perimeter); Graphics grp = null; StringFormat sf = null, sfp = null; try { grp = Graphics.FromImage(bmp); grp.CompositingQuality = CompositingQuality.HighQuality; grp.SmoothingMode = SmoothingMode.AntiAlias; sf = new StringFormat(); //Paint Back ground grp.FillRectangle(new SolidBrush(_backgroundColor), -1, -1, perimeter + _legendWidth + 1, perimeter + 1); //Align text to the right sf.Alignment = StringAlignment.Far; //Draw all wedges and legends for (int i = 0; i < _chartItems.Count; i++) { DataItem item = (DataItem)_chartItems[i]; SolidBrush brs = null; try { brs = new SolidBrush(item.ItemColor); grp.FillPie(brs, pieRect, item.StartPos, item.SweepSize); //grp.DrawPie(new Pen(_borderColor,1.2f),pieRect,item.StartPos,item.SweepSize); if (_showPercents && item.SweepSize > 10) { if (sfp == null) { sfp = new StringFormat(); sfp.Alignment = StringAlignment.Center; sfp.LineAlignment = StringAlignment.Center; } float perc = (item.SweepSize * 100.0f) / 360.0f; string percString = String.Format("{0:F0}%", perc); float px = pieRect.X + (pieRect.Width / 2); float py = pieRect.Y + (pieRect.Height / 2); double angle = item.StartPos + (item.SweepSize / 2); double rads = (angle / 180.0) * Math.PI; px += (float)(Math.Cos(rads) * perimeter / 3); py += (float)(Math.Sin(rads) * perimeter / 3); grp.DrawString(percString, new Font(_legendFontStyle, _legendFontSize), Brushes.Gray, new RectangleF(px - 30 - 1, py - 20, 60, 40), sfp); grp.DrawString(percString, new Font(_legendFontStyle, _legendFontSize), Brushes.Gray, new RectangleF(px - 30 + 1, py - 20, 60, 40), sfp); grp.DrawString(percString, new Font(_legendFontStyle, _legendFontSize), Brushes.Gray, new RectangleF(px - 30, py - 20 - 1, 60, 40), sfp); grp.DrawString(percString, new Font(_legendFontStyle, _legendFontSize), Brushes.Gray, new RectangleF(px - 30, py - 20 + 1, 60, 40), sfp); grp.DrawString(percString, new Font(_legendFontStyle, _legendFontSize), Brushes.White, new RectangleF(px - 30, py - 20, 60, 40), sfp); } grp.FillRectangle(brs, perimeter + _bufferSpace, i * _legendFontHeight + 15, 10, 10); grp.DrawRectangle(new Pen(_borderColor, 0.5f), perimeter + _bufferSpace, i * _legendFontHeight + 15, 10, 10); grp.DrawString(item.Label, new Font(_legendFontStyle, _legendFontSize), Brushes.Black, new PointF(perimeter + _bufferSpace + 20, i * _legendFontHeight + 13)); grp.DrawString(item.Value.ToString("#,###.##"), new Font(_legendFontStyle, _legendFontSize), new SolidBrush(Color.Black), perimeter + _bufferSpace + 200, i * _legendFontHeight + 13, sf); } finally { if (brs != null) { brs.Dispose(); } } } for (int i = 0; i < _chartItems.Count; i++) { DataItem item = (DataItem)_chartItems[i]; SolidBrush brs = null; try { grp.DrawPie(new Pen(_borderColor, 0.5f), pieRect, item.StartPos, item.SweepSize); } finally { if (brs != null) { brs.Dispose(); } } } //draws the border around Pie grp.DrawEllipse(new Pen(_borderColor, 2), pieRect); //draw border around legend grp.DrawRectangle(new Pen(_borderColor, 1), perimeter + _bufferSpace - 10, 10, 220, _chartItems.Count * _legendFontHeight + 30); //Draw Total under legend grp.DrawString("Total", new Font(_legendFontStyle, _legendFontSize), new SolidBrush(Color.Black), perimeter + _bufferSpace + 35, (_chartItems.Count + 1) * _legendFontHeight, sf); grp.DrawString(_total.ToString("#,###.##"), new Font(_legendFontStyle, _legendFontSize), new SolidBrush(Color.Black), perimeter + _bufferSpace + 200, (_chartItems.Count + 1) * _legendFontHeight, sf); grp.SmoothingMode = SmoothingMode.AntiAlias; } finally { if (sf != null) { sf.Dispose(); } if (grp != null) { grp.Dispose(); } } return(bmp); }