/// <summary> /// /// </summary> public override void Paint() { //calculate the size of fill RectangleF bitmapRectangle = new RectangleF(0, 0, Bitmap.Width - 1, Bitmap.Height - 1); DrawingElements.Add(new DrawBackGround(Color.White, bitmapRectangle)); RectangleF barArea = new RectangleF(1, 1, bitmapRectangle.Width - 2, bitmapRectangle.Height - 2); double valueInQuickBar = ((GraphRange)GraphData.Ranges[0]).SumOfValues; string displayValue = Convert.ToString(valueInQuickBar); if (maxValue < valueInQuickBar) { maxValue = valueInQuickBar; displayValue += "..."; } if (maxValue == 0) { maxValue = 1; } double withOfBar = (barArea.Width / maxValue) * valueInQuickBar; double widthOfLabel = ((SizeF)(Graphics.MeasureString(Convert.ToString(valueInQuickBar), textFont) + new SizeF(4, 4))).Width; if (widthOfLabel > withOfBar) { withOfBar = widthOfLabel; } RectangleF barRectangle = new RectangleF(barArea.X, barArea.Y, (float)withOfBar, (float)barArea.Height); //draw the fill Graphics.FillRectangle( new LinearGradientBrush(new PointF(0, 0), new PointF(bitmapRectangle.X + bitmapRectangle.Width, bitmapRectangle.Y + bitmapRectangle.Height), ((GraphRange)GraphData.Ranges[0]).SecondaryColor, ((GraphRange)GraphData.Ranges[0]).PrimaryColor), barRectangle); Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 1), GraphMaths.ConvertToRectangle(barRectangle)); if (displayValue.EndsWith("...")) { Graphics.DrawLine(new Pen(new SolidBrush(((GraphRange)GraphData.Ranges[0]).PrimaryColor), 1), new PointF(bitmapRectangle.X + bitmapRectangle.Width - 1, bitmapRectangle.Y + 2), new PointF(bitmapRectangle.X + bitmapRectangle.Width - 1, bitmapRectangle.Y + bitmapRectangle.Height - 2)); } //draw the text Graphics.DrawString(displayValue, textFont, new SolidBrush(textColor), barRectangle, textStringFormat); base.Paint(); }
/// <summary> /// Generates the title. /// </summary> private void GenerateTitle() { if (DrawTitle == true) { #if GRAPHDEBUG DrawingElements.Add(new DrawRectangle(debugPen, TitleRectangle)); #endif DrawingElements.Add( new DrawString(GraphData.Title, TitleFont, new SolidBrush(TitleColor), TitleRectangle, TitleStringFormat)); } }
/// <summary> /// The override for the Paint method. This method paints the graph onto the canvas. /// </summary> private void Construct() { Graphics.CompositingQuality = CompositingQuality.HighQuality; Graphics.CompositingMode = CompositingMode.SourceOver; Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; ImageAttributes ia = new ImageAttributes(); ia.SetGamma(50, ColorAdjustType.Brush); DrawingElements.Add(new DrawBackGround(Color.White, GraphCanvasRectangle)); Pen outline = new Pen(new SolidBrush(Color.DarkGray)); //DrawingElements.Add(new DrawRectangle(outline, 0, 0, Bitmap.Width - 1, Bitmap.Height - 1)); #if GRAPHDEBUG DrawingElements.Add(new DrawRectangle(debugPen, TitleRectangle)); DrawingElements.Add(new DrawRectangle(debugPen, LegendRectangle)); DrawingElements.Add(new DrawRectangle(debugPen, GraphRectangle)); #endif //graph Graphics.Clip = new Region(GraphRectangle); //adjuct the rectangle to be square if (GraphRectangle.Width > GraphRectangle.Height) { GraphRectangle = new RectangleF(GraphRectangle.X + ((GraphRectangle.Width - GraphRectangle.Height)) / 2, GraphRectangle.Y, GraphRectangle.Height, GraphRectangle.Height); } else { GraphRectangle = new RectangleF(GraphRectangle.X, GraphRectangle.Y, GraphRectangle.Width, GraphRectangle.Width); } #if GRAPHDEBUG DrawingElements.Add( new DrawString(string.Format("Width={0}, Height={1}", GraphRectangle.Width, GraphRectangle.Height), LegendFont, debugBrush, GraphRectangle, LegendStringFormat)); DrawingElements.Add(new DrawEllipse(debugPen, GraphRectangle)); #endif float total = 0; foreach (GraphRange gr in GraphData.Ranges) { total += (float)gr.SumOfValues; } float start = 0; float end = 0; float step = (360 / total); RectangleF labelRectangle = new RectangleF(GraphRectangle.X + (GraphRectangle.Width / 100 * 10), GraphRectangle.Y + (GraphRectangle.Height / 100 * 10), GraphRectangle.Width - (GraphRectangle.Width / 100 * 20), GraphRectangle.Height - (GraphRectangle.Height / 100 * 20)); RectangleF pieRectangle = new RectangleF(GraphRectangle.X + (GraphRectangle.Width / 100 * 20), GraphRectangle.Y + (GraphRectangle.Height / 100 * 20), GraphRectangle.Width - (GraphRectangle.Width / 100 * 40), GraphRectangle.Height - (GraphRectangle.Height / 100 * 40)); PointF centrePie = new PointF(pieRectangle.X + (pieRectangle.Width / 2), pieRectangle.Y + (pieRectangle.Height / 2)); ArrayList differedLabelDraw = new ArrayList(); foreach (GraphRange gr in GraphData.Ranges) { end = step * (float)gr.SumOfValues; PointF centreLabel = GraphMaths.PointOnCircleF(Convert.ToInt32(start + (end / 2)), labelRectangle); PointF edgeOfPie = GraphMaths.PointOnCircleF(Convert.ToInt32(start + (end / 2)), pieRectangle); #if GRAPHDEBUG DrawingElements.Add(new DrawLine(debugPen, centreLabel, centrePie)); DrawingElements.Add(new DrawPie(debugPen, pieRectangle, start - 90, end)); #endif DrawingElements.Add(new DrawLine(outline, centreLabel, edgeOfPie)); DrawingElements.Add( new FillPie( new LinearGradientBrush(pieRectangle, gr.PrimaryColor, gr.SecondaryColor, LinearGradientMode.ForwardDiagonal), pieRectangle, start - 90, end)); if (_textLabels == true) { DrawingElements.Add(new FillRectangle(new SolidBrush(Color.White), GraphHelpers.TextRectangleFromCentre(Graphics, gr.Label, LegendFont, centreLabel))); DrawingElements.Add( new DrawString(gr.Label, LegendFont, new SolidBrush(Color.Black), GraphHelpers.TextRectangleFromCentre(Graphics, gr.Label, LegendFont, centreLabel), null)); } else { DrawingElements.Add(new FillRectangle(new SolidBrush(Color.White), GraphHelpers.TextRectangleFromCentre(Graphics, gr.SumOfValues. ToString("F"), LegendFont, centreLabel))); DrawingElements.Add( new DrawString(gr.SumOfValues.ToString("F"), LegendFont, new SolidBrush(Color.Black), GraphHelpers.TextRectangleFromCentre(Graphics, gr.SumOfValues.ToString("F"), LegendFont, centreLabel), null)); } differedLabelDraw.Add(centreLabel); start = start + end; } Graphics.ResetClip(); //title if (DrawTitle == true) { #if GRAPHDEBUG DrawingElements.Add(new DrawRectangle(debugPen, TitleRectangle)); #endif DrawingElements.Add( new DrawString(GraphData.Title, TitleFont, new SolidBrush(TitleColor), TitleRectangle, TitleStringFormat)); } //legend if (DrawLegend == true) { //work out text height int textHeight = (int)((Graphics.MeasureString("X", LegendFont).Height) / 100 * 120); #if GRAPHDEBUG DrawingElements.Add( new DrawRectangle(debugPen, LegendRectangle.X, LegendRectangle.Y, LegendRectangle.Width - 1, GraphData.Ranges.Count * textHeight)); #endif DrawingElements.Add(new FillRectangle(new SolidBrush(Color.White), LegendRectangle.X, LegendRectangle.Y, LegendRectangle.Width - 1, GraphData.Ranges.Count * textHeight)); int lentry = 0; foreach (GraphRange gr in GraphData.Ranges) { RectangleF currentRectangle = new RectangleF(LegendRectangle.X + 20, (textHeight * lentry++) + LegendRectangle.Y, LegendRectangle.Width - 20, textHeight); RectangleF colorRectangle = currentRectangle; colorRectangle.Offset(-20, 0); colorRectangle.Width = 20; #if GRAPHDEBUG DrawingElements.Add(new DrawRectangle(debugPen, currentRectangle)); DrawingElements.Add(new DrawRectangle(debugPen, colorRectangle)); #endif string lable = gr.Label; if (lable.Length > 26) { lable = lable.Substring(0, 26); } string val = gr.SumOfValues.ToString("F"); DrawingElements.Add(new DrawString( string.Format("{0} = {1}", lable, val), LegendFont, new SolidBrush(Color.Black), currentRectangle, LegendStringFormat)); char symbol = (char)162; DrawingElements.Add(new DrawString( symbol.ToString(), new Font("Wingdings 2", 12), new SolidBrush(gr.PrimaryColor), colorRectangle, LegendStringFormat)); } DrawingElements.Add( new DrawRectangle(outline, LegendRectangle.X, LegendRectangle.Y, LegendRectangle.Width - 1, GraphData.Ranges.Count * textHeight)); } }
/// <summary> /// The chart paint method. /// </summary> public override void Paint() { DrawingElements.Add(new DrawBackGround(Color.White, GraphRectangle)); DrawLineGraph(); base.Paint(); }