void chart_PostPaint(object sender, ChartPaintEventArgs e) { if (!(e.ChartElement is Series)) return; ChartGraphics cg = e.ChartGraphics; foreach (Series s in e.Chart.Series) { double max = s.Points.FindMaxByValue().YValues[0]; for (int i = 0; i < s.Points.Count; i++) { if (s.Points[i].YValues[0] == max) { // Get relative coordinates of the data point System.Drawing.PointF pos = System.Drawing.PointF.Empty; pos.X = (float)cg.GetPositionFromAxis(s.ChartArea, AxisName.X, s.Points[i].XValue); pos.Y = (float)cg.GetPositionFromAxis(s.ChartArea, AxisName.Y, max); // Convert relative coordinates to absolute coordinates. pos = cg.GetAbsolutePoint(pos); // Draw concentric circles at the data point for (int radius = 10; radius < 40; radius += 10) { cg.Graphics.DrawEllipse( System.Drawing.Pens.Red, pos.X - radius / 2, pos.Y - radius / 2, radius, radius); } } } } }
private void chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (graph_type == "z-score") { Chart my_chart = (Chart)sender; ChartArea area = my_chart.ChartAreas[0]; Axis ax = chart.ChartAreas[0].AxisX; Axis ay = chart.ChartAreas[0].AxisY; Graphics graph = e.ChartGraphics.Graphics; PointF point1 = PointF.Empty; PointF point2 = PointF.Empty; point1.X = (float)ax.ValueToPixelPosition(chart.ChartAreas[0].AxisX.Minimum); point1.Y = (float)ay.ValueToPixelPosition(-1.0); point2.X = (float)ax.ValueToPixelPosition(chart.ChartAreas[0].AxisX.Maximum); point2.Y = (float)ay.ValueToPixelPosition(-1.0); float[] dashValues = { 2, 2, 2, 2 }; Pen blackPen = new Pen(Color.DimGray, 0.25f); blackPen.DashPattern = dashValues; graph.DrawLine(blackPen, point1, point2); } }
protected override void OnPostPaint(ChartPaintEventArgs e) { waiting = 0; UpdateData(); waiting = 0; base.OnPostPaint(e); }
private void chart1_PrePaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { foreach (DataPoint p in chart1.Series[0].Points) { p["Exploded"] = "True"; } }
private void PaintElement (ChartGraphics g, object element, ElementPosition position) { ChartPaintEventArgs e = new ChartPaintEventArgs (this, element, g, position); OnPrePaint (e); OnPostPaint (e); }
private void Chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { // Painting series object if (sender is System.Windows.Forms.DataVisualization.Charting.ChartArea) { ChartArea area = (ChartArea)sender; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; RectangleF rect = new RectangleF(area.Position.X, area.Position.Y, area.Position.Width, 6); rect = e.ChartGraphics.GetAbsoluteRectangle(rect); e.ChartGraphics.Graphics.DrawString(area.Name, new Font("Arial", 10), Brushes.Black, rect, format); } }
/// <summary> /// Chart post paint event handler. /// Used to draw the "connection" lines between the original and supplemental pies. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void chart_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (sender is ChartArea) { ChartArea area = (ChartArea)sender; if (this.supplementalChartArea != null && area.Name == this.supplementalChartArea.Name) { // Get position of the plotting areas in pixels RectangleF originalPosition = GetChartAreaPlottingPosition(this.originalChartArea, e.ChartGraphics); RectangleF supplementalPosition = GetChartAreaPlottingPosition(this.supplementalChartArea, e.ChartGraphics); // Get coordinates of the "connection" lines PointF p1 = GetRotatedPlotAreaPoint(supplementalPosition, 325f); PointF p2 = GetRotatedPlotAreaPoint(supplementalPosition, 215f); PointF p3 = GetRotatedPlotAreaPoint(originalPosition, 90f - this.collectedPieSliceAngle / 2f); PointF p4 = GetRotatedPlotAreaPoint(originalPosition, 90f + this.collectedPieSliceAngle / 2f); // Draw "connection lines" using (Pen pen = new Pen(this.ConnectionLinesColor, 1)) { e.ChartGraphics.Graphics.DrawLine(pen, p1, p3); e.ChartGraphics.Graphics.DrawLine(pen, p2, p4); } } } }
private void PaintElement(ChartGraphics g, object element, ElementPosition position) { ChartPaintEventArgs e = new ChartPaintEventArgs(this, element, g, position); OnPrePaint(e); OnPostPaint(e); }
private void chart1_PrePaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { // read the calculated Box Size - CurrentBoxSize attribute string calculatedBoxSize = chart1.Series["Default"]["CurrentBoxSize"].ToString(); // update chart title chart1.Titles[0].Text = "Renko chart, Box Size = " + calculatedBoxSize; }
private void chart2_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { System.Drawing.Font drawFont = new System.Drawing.Font("Verdana", 8); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); if (!(string.IsNullOrEmpty(Xg) && string.IsNullOrEmpty(Yg))) { e.ChartGraphics.Graphics.DrawString("ELong=" + Xg + "\n" + "Fuerza=" + Yg, drawFont, drawBrush, x + 5, y - 2); e.ChartGraphics.Graphics.DrawRectangle(new Pen(Color.Red, 3), r1); } }
/// <summary> /// Chart Paint event handler. /// </summary> private void Chart_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (e.ChartElement is ChartArea) { ChartArea area = (ChartArea)e.ChartElement; // call the paint method. if (ChartAreas.IndexOf(area.Name) >= 0 && enabled) { PaintDataTable(e); } } }
private static void ChartOnPostPaint(object sender, ChartPaintEventArgs chartPaintEventArgs) { // Subscribing to PostPaint allows us to get the correct // bounds of the chart to send to the user. Some other events // don't seem to be sufficient. Chart ptrChart = sender as Chart; if (ptrChart == null) { return; } ptrChart.PostPaint -= ChartOnPostPaint; // Only run once OnZoomChanged(ptrChart); }
private void Chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (e.ChartElement is ChartArea) { ChartArea area = (ChartArea)e.ChartElement; if (area.Name == "Default") { // If Connection line is not checked return if (!ConnectionLine.Checked) { return; } double max; double min; double xMax; double xMin; // Find Minimum and Maximum values FindMaxMin(out max, out min, out xMax, out xMin); // Take Graphics object from chart Graphics graph = e.ChartGraphics.Graphics; // Convert X and Y values to screen position float pixelYMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, max); float pixelXMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, xMax); float pixelYMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, min); float pixelXMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, xMin); PointF point1 = PointF.Empty; PointF point2 = PointF.Empty; // Set Maximum and minimum points point1.X = pixelXMax; point1.Y = pixelYMax; point2.X = pixelXMin; point2.Y = pixelYMin; // Convert relative coordinates to absolute coordinates. point1 = e.ChartGraphics.GetAbsolutePoint(point1); point2 = e.ChartGraphics.GetAbsolutePoint(point2); // Draw connection line graph.DrawLine(new Pen(Color.FromArgb(26, 59, 105), 2), point1, point2); } } }
private void Chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { // Painting series object if (e.ChartElement is System.Windows.Forms.DataVisualization.Charting.Series) { // Add custom painting only to the series with name "Sereis2" Series series = (Series)e.ChartElement; if (series.Name == "Series2") { // Find data point with maximum Y value DataPoint dataPoint = series.Points.FindMaxByValue(); // Image path System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm) this.ParentForm; string fileNameString = mainForm.applicationPath + "\\Images\\money.png"; // Load bitmap from file System.Drawing.Image bitmap = Bitmap.FromFile(fileNameString); // Set Red color as transparent ImageAttributes attrib = new ImageAttributes(); attrib.SetColorKey(Color.Red, Color.Red, ColorAdjustType.Default); // Calculates marker position depending on the data point X and Y values RectangleF imagePosition = RectangleF.Empty; imagePosition.X = (float)e.ChartGraphics.GetPositionFromAxis( "Default", AxisName.X, dataPoint.XValue); imagePosition.Y = (float)e.ChartGraphics.GetPositionFromAxis( "Default", AxisName.Y, dataPoint.YValues[0]); imagePosition = e.ChartGraphics.GetAbsoluteRectangle(imagePosition); imagePosition.Width = bitmap.Width; imagePosition.Height = bitmap.Height; imagePosition.Y -= bitmap.Height; imagePosition.X -= bitmap.Width / 2; // Draw image e.ChartGraphics.Graphics.DrawImage(bitmap, Rectangle.Round(imagePosition), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, attrib); // Dispose image object bitmap.Dispose(); } } }
public void PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (chart1.Series[0].Points.Count <= 0) { return; } Axis ax = chart1.ChartAreas[0].AxisX; Axis ay = chart1.ChartAreas[0].AxisY; Graphics g = e.ChartGraphics.Graphics; using (StringFormat fmt = new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far }) foreach (Series s in chart1.Series) { foreach (DataPoint dp in s.Points) { if (dp.Tag == null) { break; } SizeF sz = (SizeF)dp.Tag; double vx2 = dp.XValue + sz.Width; double vy2 = dp.YValues[0] + sz.Height; int x1 = (int)ax.ValueToPixelPosition(dp.XValue); int y1 = (int)ay.ValueToPixelPosition(dp.YValues[0]); int x2 = (int)ax.ValueToPixelPosition(vx2); int y2 = (int)ay.ValueToPixelPosition(vy2); Rectangle rect = Rectangle.FromLTRB(x1, y2, x2, y1); using (Pen pen = new Pen(Color.Black)) g.DrawRectangle(pen, rect); g.DrawString(dp.Label, Font, Brushes.Black, rect, fmt); } } }
private void chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (sender is ChartArea) { Series series = chart1.Series["Tasks"]; // Take Graphics object from chart Graphics graph = e.ChartGraphics.Graphics; for (int i = 0; i < series.Points.Count; i++) { if ((i + 1) < series.Points.Count && i != 1 && i != 3) { double p1X, p2X, p1Y, p2Y; p1X = series.Points[i].XValue; p2X = series.Points[i + 1].XValue; p1Y = series.Points[i].YValues[1]; p2Y = series.Points[i + 1].YValues[0]; float pixelX1 = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, p1Y); float pixelY1 = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, p1X); float pixelX2 = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, p2Y); float pixelY2 = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, p2X); PointF point1 = PointF.Empty; PointF point2 = PointF.Empty; PointF point3 = PointF.Empty; point1.X = pixelX1; point1.Y = pixelY1; point2.X = pixelX2; point2.Y = pixelY2; // make the middle right-angle point point3.X = pixelX2; point3.Y = pixelY1; // If 3D, we need to transform the 3D points into 2D points if (checkBoxShow3D.Checked) { // Get Z position for this series, and then add half of series depth so that // custom drawing occurs at the front of the data points float ZPosition = chart1.ChartAreas["Default"].GetSeriesZPosition(series); ZPosition = ZPosition + (float)0.5 * (chart1.ChartAreas["Default"].GetSeriesDepth(series)); // Create 3D points for the 2D points Point3D[] My3DPoint = new Point3D[3]; My3DPoint[0] = new Point3D(point1.X, point1.Y, ZPosition); My3DPoint[1] = new Point3D(point2.X, point2.Y, ZPosition); My3DPoint[2] = new Point3D(point3.X, point3.Y, ZPosition); // Transform so that new 2D points has new X and Y values that take into account the Z position chart1.ChartAreas["Default"].TransformPoints(My3DPoint); point1 = My3DPoint[0].PointF; point2 = My3DPoint[1].PointF; point3 = My3DPoint[2].PointF; } // Convert relative coordinates to absolute coordinates. point1 = e.ChartGraphics.GetAbsolutePoint(point1); point2 = e.ChartGraphics.GetAbsolutePoint(point2); point3 = e.ChartGraphics.GetAbsolutePoint(point3); // Draw connection line graph.DrawLine(new Pen(Color.Black, 2), point1, point3); graph.DrawLine(new Pen(Color.Black, 2), point3, point2); DrawArrow(graph, Color.Black, point2, point3, 22.5); } } } }
private void chart1_PostPaint(object sender, ChartPaintEventArgs e) { if (e.ChartElement is Chart) { // PostPaint(e); } }
public void PostPaint(ChartPaintEventArgs e) { // create text to draw String TextToDraw; TextToDraw = ""; TextToDraw += ""; // get graphics tools Graphics g = e.ChartGraphics.Graphics; Font DrawFont = System.Drawing.SystemFonts.CaptionFont; Brush DrawBrush = Brushes.Black; // see how big the text will be int TxtWidth = (int)g.MeasureString(TextToDraw, DrawFont).Width; int TxtHeight = (int)g.MeasureString(TextToDraw, DrawFont).Height; // where to draw int x = 15; // a few pixels from the left border int y = (int)e.Chart.Height; y = y - TxtHeight - 5; // a few pixels off the bottom // draw the string g.DrawString(TextToDraw, DrawFont, DrawBrush, x, y); }
private void OnPostPaintDepth(object sender, ChartPaintEventArgs e) { /*ChartGraphics cg = e.ChartGraphics; PointF p = new PointF { X = (float)cg.GetPositionFromAxis(kDepthChartAreaName, AxisName.X, m_vwap) }; p = cg.GetAbsolutePoint(p); Pen bp = new Pen(Color.Black); cg.Graphics.DrawLine(bp, p.X, 0, p.X, m_depthChart.Height);*/ }
private void chart1_PrePaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (e.ChartElement is Chart) { // Position point chart type series on the points of the box plot to display labels chart1.Series["BoxPlotLabels"].Points[0].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[0]; chart1.Series["BoxPlotLabels"].Points[1].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[1]; chart1.Series["BoxPlotLabels"].Points[2].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[2]; chart1.Series["BoxPlotLabels"].Points[3].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[3]; chart1.Series["BoxPlotLabels"].Points[4].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[4]; chart1.Series["BoxPlotLabels"].Points[5].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[5]; chart1.Series["BoxPlotLabels"].Points[6].Label = ""; chart1.Series["BoxPlotLabels"].Points[7].Label = ""; if (checkBoxShowUnusual.Checked) { if (chart1.Series["BoxPlotSeries"].Points[0].YValues.Length > 6) { chart1.Series["BoxPlotLabels"].Points[6].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[6] - 3; chart1.Series["BoxPlotLabels"].Points[6].Label = "Unusual data point"; } if (chart1.Series["BoxPlotSeries"].Points[0].YValues.Length > 8) { chart1.Series["BoxPlotLabels"].Points[7].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[8] + 3; chart1.Series["BoxPlotLabels"].Points[7].Label = "Unusual data point"; } else if (chart1.Series["BoxPlotSeries"].Points[0].YValues.Length > 7) { chart1.Series["BoxPlotLabels"].Points[7].YValues[0] = chart1.Series["BoxPlotSeries"].Points[0].YValues[7] + 3; chart1.Series["BoxPlotLabels"].Points[7].Label = "Unusual data point"; } } // Define labels int whiskerPercentile = (3 - comboBoxPercentiles.SelectedIndex) * 5; chart1.Series["BoxPlotLabels"].Points[0].Label = whiskerPercentile.ToString() + "th Percentile"; chart1.Series["BoxPlotLabels"].Points[1].Label = (100 - whiskerPercentile).ToString() + "th Percentile"; if (whiskerPercentile == 0) { chart1.Series["BoxPlotLabels"].Points[0].Label = "Minimum"; chart1.Series["BoxPlotLabels"].Points[1].Label = "Maximum"; } chart1.Series["BoxPlotLabels"].Points[2].Label = "25th Percentile (LQ)"; chart1.Series["BoxPlotLabels"].Points[3].Label = "75th Percentile (UQ)"; chart1.Series["BoxPlotLabels"].Points[4].Label = (checkBoxShowAverage.Checked) ? "Average/Mean" : ""; chart1.Series["BoxPlotLabels"].Points[5].Label = (checkBoxShowMedian.Checked) ? "Median" : ""; // Add strip lines chart1.ChartAreas["Data Chart Area"].AxisY.StripLines.Clear(); StripLine stripLine = new StripLine(); stripLine.BackColor = Color.FromArgb(60, 252, 180, 65); stripLine.IntervalOffset = chart1.Series["BoxPlotLabels"].Points[2].YValues[0]; stripLine.StripWidth = chart1.Series["BoxPlotLabels"].Points[3].YValues[0] - stripLine.IntervalOffset; stripLine.Text = "data points\n50% of"; stripLine.Font = new Font("Microsoft Sans Serif", 7); stripLine.TextOrientation = TextOrientation.Rotated270; stripLine.TextLineAlignment = StringAlignment.Center; stripLine.TextAlignment = StringAlignment.Near; chart1.ChartAreas["Data Chart Area"].AxisY.StripLines.Add(stripLine); stripLine = new StripLine(); stripLine.BackColor = Color.FromArgb(60, 252, 180, 65); stripLine.IntervalOffset = chart1.Series["BoxPlotLabels"].Points[0].YValues[0]; stripLine.StripWidth = chart1.Series["BoxPlotLabels"].Points[1].YValues[0] - stripLine.IntervalOffset; stripLine.ForeColor = Color.FromArgb(120, Color.Black); stripLine.Text = (100 - whiskerPercentile * 2).ToString() + "% of data points"; stripLine.Font = new Font("Microsoft Sans Serif", 7); stripLine.TextOrientation = TextOrientation.Rotated270; stripLine.TextLineAlignment = StringAlignment.Center; chart1.ChartAreas["Data Chart Area"].AxisY.StripLines.Add(stripLine); } }
private void chart1_PrePaint(object sender, ChartPaintEventArgs e) { //e.ChartGraphics.Graphics.DrawLine(new Pen(Color.Red), -20 + mouse_xPos, -20 + mouse_yPos, 20 + mouse_xPos, 20 + mouse_yPos); //e.ChartGraphics.Graphics.DrawLine(new Pen(Color.Red), 20 + mouse_xPos, -20 + mouse_yPos, -20 + mouse_xPos, 20 + mouse_yPos); }
protected virtual void OnPrePaint(ChartPaintEventArgs e) { }
private void chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (sender is ChartArea) { ChartArea area = (ChartArea)sender; if (area.Name == "Default") { Point3D [] pt3d = new Point3D[4]; pt3d[0] = new Point3D(); pt3d[1] = new Point3D(); pt3d[2] = new Point3D(); pt3d[3] = new Point3D(); float depth = (float)area.GetSeriesDepth(chart1.Series[0]); float zpos = (float)area.GetSeriesZPosition(chart1.Series[0]); pt3d[0].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[7].XValue); pt3d[0].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[7].YValues[1]); pt3d[0].Z = depth; pt3d[1].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[6].XValue); pt3d[1].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[6].YValues[0]); pt3d[1].Z = depth; pt3d[2].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[3].XValue); pt3d[2].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[3].YValues[1]); pt3d[2].Z = depth; pt3d[3].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[2].XValue); pt3d[3].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[2].YValues[0]); pt3d[3].Z = depth; area.TransformPoints(pt3d); PointF ptF1 = new PointF(); PointF ptF2 = new PointF(); PointF ptF3 = new PointF(); PointF ptF4 = new PointF(); PointF ptF5 = new PointF(); PointF ptF6 = new PointF(); ptF1 = e.ChartGraphics.GetAbsolutePoint(pt3d[0].PointF); ptF3 = e.ChartGraphics.GetAbsolutePoint(pt3d[1].PointF); ptF4 = e.ChartGraphics.GetAbsolutePoint(pt3d[2].PointF); ptF6 = e.ChartGraphics.GetAbsolutePoint(pt3d[3].PointF); ptF2.X = ptF3.X; ptF2.Y = ptF1.Y; ptF5.X = ptF6.X; ptF5.Y = ptF4.Y; // Take Graphics object from chart Graphics graph = e.ChartGraphics.Graphics; graph.DrawLine(new Pen(Color.Black, 1), ptF1, ptF2); graph.DrawLine(new Pen(Color.Black, 1), ptF2, ptF3); graph.DrawLine(new Pen(Color.Black, 1), ptF4, ptF5); graph.DrawLine(new Pen(Color.Black, 1), ptF5, ptF6); DrawArrow(graph, Color.Black, ptF3, ptF2, 22.5); DrawArrow(graph, Color.Black, ptF6, ptF5, 22.5); } } }
private void chart_PostPaint(object sender, ChartPaintEventArgs e) { var chartArea = e.ChartElement as ChartArea; if (chartArea != null) { ChartGraphics chartGraphics = e.ChartGraphics; using (Pen p = new Pen(Color.DarkGray)) { double xmin = chartArea.AxisX.ScaleView.ViewMinimum; double xmax = chartArea.AxisX.ScaleView.ViewMaximum; double ymin = chartArea.AxisY.ScaleView.ViewMinimum; double ymax = chartArea.AxisY.ScaleView.ViewMaximum; if (xmin > ymax || ymin > xmax) return; PointF start = PointF.Empty; start.X = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisX.AxisName, Math.Max(xmin, ymin)); start.Y = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisY.AxisName, Math.Max(xmin, ymin)); PointF end = PointF.Empty; end.X = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisX.AxisName, Math.Min(xmax, ymax)); end.Y = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisY.AxisName, Math.Min(xmax, ymax)); chartGraphics.Graphics.DrawLine(p, chartGraphics.GetAbsolutePoint(start), chartGraphics.GetAbsolutePoint(end)); } } }
/// <summary> /// This method does all the work for the painting of the data table. /// </summary> private void PaintDataTable(System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { ChartArea area = (ChartArea)e.ChartElement; // get the rect of the chart area RectangleF rect = e.ChartGraphics.GetAbsoluteRectangle(area.Position.ToRectangleF()); // get the inner plot position ElementPosition elemPos = area.InnerPlotPosition; // find the coordinates of the inner plot position float x = rect.X + (rect.Width / 100 * elemPos.X); float y = rect.Y + (rect.Height / 100 * elemPos.Y); float ChartAreaBottomY = rect.Y + rect.Height; // offset the bottom by the width+1 of the scrollbar if it is visible if (area.AxisX.ScrollBar.IsVisible && !area.AxisX.ScrollBar.IsPositionedInside) { ChartAreaBottomY -= ((float)area.AxisX.ScrollBar.Size + 1); } float width = (rect.Width / 100 * elemPos.Width); float height = (rect.Height / 100 * elemPos.Height); // find the height of the font that will be used Font axisFont = area.AxisX.LabelStyle.Font; string testString = "ForFontHeight"; SizeF axisFontSize = e.ChartGraphics.Graphics.MeasureString(testString, axisFont); // find the height of the font that will be used Font titleFont = area.AxisX.TitleFont; testString = area.AxisX.Title; SizeF titleFontSize = e.ChartGraphics.Graphics.MeasureString(testString, titleFont); int seriesCount = 0; // for each series that is attached to the chart area, // draw some boxes around the labels in the color provided for (int i = e.Chart.Series.Count - 1; i >= 0; i--) { if (area.Name == e.Chart.Series[i].ChartArea) { seriesCount++; } } // now, if a box was actually drawn, then draw // the verticle lines to separate the columns of the table. if (seriesCount > 0) { for (int i = 0; i < e.Chart.Series.Count; i++) { if (area.Name == e.Chart.Series[i].ChartArea) { double min = area.AxisX.Minimum; double max = area.AxisX.Maximum; // modify the min value for the current axis view if (area.AxisX.ScaleView.Position - 1 > min) { min = area.AxisX.ScaleView.Position - 1; } // modify the max value for the currect axis view if ((area.AxisX.ScaleView.Position + area.AxisX.ScaleView.Size + 0.5) < max) { max = area.AxisX.ScaleView.Position + area.AxisX.ScaleView.Size + 0.5; } // find the starting point that will be display. // this is dependent on the current axis view. // this sample assumes the same number of points in each // series so always take from the zeroth series int pointIndex = 0; foreach (DataPoint pt in ChartObj.Series[0].Points) { if (pt.XValue > min) { break; } pointIndex++; } bool TableLegendDrawn = false; for (double AxisValue = min; AxisValue < max; AxisValue++) { float pixelX = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, AxisValue); float nextPixelX = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, AxisValue + 1); float pixelY = ChartAreaBottomY - titleFontSize.Height - (seriesCount * axisFontSize.Height); PointF point1 = PointF.Empty; PointF point2 = PointF.Empty; // Set Maximum and minimum points point1.X = pixelX; point1.Y = 0; // Convert relative coordinates to absolute coordinates. point1 = e.ChartGraphics.GetAbsolutePoint(point1); point2.X = point1.X; point2.Y = ChartAreaBottomY - titleFontSize.Height; point1.Y = pixelY; // Draw connection line e.ChartGraphics.Graphics.DrawLine(new Pen(borderColor), point1, point2); point2.X = nextPixelX; point2.Y = 0; point2 = e.ChartGraphics.GetAbsolutePoint(point2); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // for each series draw one value in the column int row = 0; foreach (Series ser in ChartObj.Series) { if (area.Name == ser.ChartArea) { if (!TableLegendDrawn) { // draw the series color box e.ChartGraphics.Graphics.FillRectangle(new SolidBrush(ser.Color), x - 10, row * (axisFont.Height) + (point1.Y), 10, axisFontSize.Height); e.ChartGraphics.Graphics.DrawRectangle(new Pen(borderColor), x - 10, row * (axisFont.Height) + (point1.Y), 10, axisFontSize.Height); e.ChartGraphics.Graphics.FillRectangle(new SolidBrush(tableColor), x, row * (axisFont.Height) + (point1.Y), width, axisFontSize.Height); e.ChartGraphics.Graphics.DrawRectangle(new Pen(borderColor), x, row * (axisFont.Height) + (point1.Y), width, axisFontSize.Height); } if (pointIndex < ser.Points.Count) { string label = ser.Points[pointIndex].YValues[0].ToString(); RectangleF textRect = new RectangleF(point1.X, row * (axisFont.Height) + (point1.Y + 1), point2.X - point1.X, axisFont.Height); e.ChartGraphics.Graphics.DrawString(label, axisFont, new SolidBrush(area.AxisX.LabelStyle.ForeColor), textRect, format); } row++; } } TableLegendDrawn = true; pointIndex++; } // do this only once so break! break; } } } }
private void Chart1_PrePaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e) { if (e.ChartElement is ChartArea) { ChartArea area = (ChartArea)e.ChartElement; if (area.Name == "Default") { double max; double min; double xMax; double xMin; // Find Minimum and Maximum values FindMaxMin(out max, out min, out xMax, out xMin); // Take Graphics object from chart Graphics graph = e.ChartGraphics.Graphics; // Convert X and Y values to screen position float pixelYMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, max); float pixelXMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, xMax); float pixelYMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, min); float pixelXMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, xMin); float XMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, area.AxisX.Minimum); float XMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, area.AxisX.Maximum); // Specify with of triangle float width = 3; // Set Maximum points PointF [] points = new PointF[3]; points[0].X = pixelXMax - width; points[0].Y = pixelYMax - width - 2; points[1].X = pixelXMax + width; points[1].Y = pixelYMax - width - 2; points[2].X = pixelXMax; points[2].Y = pixelYMax - 1; // Convert relative coordinates to absolute coordinates. points[0] = e.ChartGraphics.GetAbsolutePoint(points[0]); points[1] = e.ChartGraphics.GetAbsolutePoint(points[1]); points[2] = e.ChartGraphics.GetAbsolutePoint(points[2]); // Draw Maximum trangle Pen darkPen = new Pen(Color.FromArgb(26, 59, 105), 1); graph.FillPolygon(new SolidBrush(Color.FromArgb(220, 252, 180, 65)), points); graph.DrawPolygon(darkPen, points); points[0].X = XMin; points[1].X = XMax; points[0].Y = points[1].Y = pixelYMax; // Convert relative coordinates to absolute coordinates. points[0] = e.ChartGraphics.GetAbsolutePoint(points[0]); points[1] = e.ChartGraphics.GetAbsolutePoint(points[1]); graph.DrawLine(darkPen, points[0], points[1]); // Set Minimum points points = new PointF[3]; points[0].X = pixelXMin - width; points[0].Y = pixelYMin + width + 2; points[1].X = pixelXMin + width; points[1].Y = pixelYMin + width + 2; points[2].X = pixelXMin; points[2].Y = pixelYMin + 1; // Convert relative coordinates to absolute coordinates. points[0] = e.ChartGraphics.GetAbsolutePoint(points[0]); points[1] = e.ChartGraphics.GetAbsolutePoint(points[1]); points[2] = e.ChartGraphics.GetAbsolutePoint(points[2]); // Draw Minimum trangle graph.FillPolygon(new SolidBrush(Color.FromArgb(220, 224, 64, 10)), points); graph.DrawPolygon(darkPen, points); points[0].X = XMin; points[1].X = XMax; points[0].Y = points[1].Y = pixelYMin; // Convert relative coordinates to absolute coordinates. points[0] = e.ChartGraphics.GetAbsolutePoint(points[0]); points[1] = e.ChartGraphics.GetAbsolutePoint(points[1]); graph.DrawLine(darkPen, points[0], points[1]); } } }
private void chart1_PostPaint(object sender, ChartPaintEventArgs e) { Debug.WriteLine(e.ChartElement); }
/// <summary> /// Handles the PostPaint event of the mainChart control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs"/> instance containing the event data.</param> private void mainChart_PostPaint(object sender, ChartPaintEventArgs e) { // Check if the sender is a cell of the Legend if (sender is LegendCell) { // Get the LegendCell LegendCell legendCell = sender as LegendCell; // Ensure it's one of the items created by this class if (legendCell.Name.IndexOf("ActivityItem") > -1) { // Get the index out of the cell's name index = Convert.ToInt32(legendCell.Name.Substring(12)); // Set the line color Color lineColor = myAlternateLineColors.FirstColor; // Set the alternate line colors up if necessary if (myAlternateLineColors.Enabled == true) { if (index % 2 != 0) lineColor = myAlternateLineColors.SecondColor; } // Check if this series is using Indexed x values bool isIndexed = (mySeries[mySeriesAssignment[index]].IsXValueIndexed == true); // Get the AxisType for X and Y axes AxisName myYAxisName; if (mySeries[mySeriesAssignment[index]].YAxisType == AxisType.Primary) myYAxisName = AxisName.Y; else myYAxisName = AxisName.Y2; // The first point of the horizontal line is the end of the legend cell (left aligned), // or beginning of legend cell (right aligned) PointF firstPoint = new PointF(); if (myLegend.Docking == Docking.Right) { firstPoint.X = e.Position.X - myLeftPadding; firstPoint.Y = e.Position.Y + (e.Position.Height / 2); } else { firstPoint.X = e.Position.X + e.ChartGraphics.GetRelativeSize((e.ChartGraphics.Graphics.MeasureString(legendCell.Text, mySecondCellFont))).Width + 1; firstPoint.Y = e.Position.Y + (e.Position.Height / 2); } // The second point of the horizontal line is straight to the right of the first point, on // top of the desired point PointF secondPoint = new PointF(); if (isIndexed) secondPoint.X = (float)e.ChartGraphics.GetPositionFromAxis(mySeries[mySeriesAssignment[index]].ChartArea, AxisName.X, myPointIndex[index] + 1); else secondPoint.X = (float)e.ChartGraphics.GetPositionFromAxis(mySeries[mySeriesAssignment[index]].ChartArea, AxisName.X, mySeries[mySeriesAssignment[index]].Points[myPointIndex[index]].XValue); secondPoint.Y = firstPoint.Y; // Convert first and second point of horizontal line to absolute co-ordinates firstPoint = e.ChartGraphics.GetAbsolutePoint(firstPoint); secondPoint = e.ChartGraphics.GetAbsolutePoint(secondPoint); // Draw the first line e.ChartGraphics.Graphics.DrawLine(new Pen(lineColor, myLineThickness), firstPoint, secondPoint); // The first point of the vertical line is the second point of the horizontal line. // The second point of the vertical line is the datapoint itself PointF thirdPoint = new PointF(); if (isIndexed) thirdPoint.X = (float)e.ChartGraphics.GetPositionFromAxis(mySeries[mySeriesAssignment[index]].ChartArea, AxisName.X, myPointIndex[index] + 1); else thirdPoint.X = (float)e.ChartGraphics.GetPositionFromAxis(mySeries[mySeriesAssignment[index]].ChartArea, AxisName.X, mySeries[mySeriesAssignment[index]].Points[myPointIndex[index]].XValue); thirdPoint.Y = (float)e.ChartGraphics.GetPositionFromAxis(mySeries[mySeriesAssignment[index]].ChartArea, myYAxisName, mySeries[mySeriesAssignment[index]].Points[myPointIndex[index]].YValues[0]); // Convert to the third point to absolute co-ordinates thirdPoint = e.ChartGraphics.GetAbsolutePoint(thirdPoint); // Draw the vertical line e.ChartGraphics.Graphics.DrawLine(new Pen(lineColor, myLineThickness), secondPoint, thirdPoint); // Fill the circle Brush myFillBrush = new SolidBrush(mySeries[mySeriesAssignment[index]].Color); e.ChartGraphics.Graphics.FillEllipse(myFillBrush, new RectangleF(thirdPoint.X - myCirclePointRadius, thirdPoint.Y - myCirclePointRadius, myCirclePointRadius * 2, myCirclePointRadius * 2)); // Draw the circle e.ChartGraphics.Graphics.DrawEllipse(new Pen(myCircleOutlineColor, myCircleOutlineThickness), thirdPoint.X - myCirclePointRadius, thirdPoint.Y - myCirclePointRadius, myCirclePointRadius * 2, myCirclePointRadius * 2); } else if (legendCell.Name.IndexOf("ActivityLeftPadding") > -1) { // Store the left cell's width incase the legend is right-docked myLeftPadding = e.Position.Width; } } }
protected virtual void OnPrePaint (ChartPaintEventArgs e) { }
private void FillChart(object sender, ChartPaintEventArgs e) { Logger.Enter(); /* dbDataSet.settingsRow opt = Db.Instance.dSet.settings.FindByid(1); DateTime date = DateTime.Now; bool today = false; const int delta = 15; if(date.Date == DateTime.Now.Date) today = true; int nIters = opt.EndTime.Subtract(opt.StartTime).Minutes / delta; WaitDialog wd = new WaitDialog(0, today ? nIters * 2 : nIters, 1); wd.Show(); wd.Refresh(); chart1.ChartAreas[0].AxisX.Interval = 60; chart1.ChartAreas[0].AxisX.IntervalOffset = 0; chart1.ChartAreas[0].AxisX.IsStartedFromZero = true; chart1.Series["seriesPresent"].Points.Clear(); chart1.Series["seriesPrognosed"].Points.Clear(); Dictionary<DateTime, int> present = GetPresentData(date); Dictionary<DateTime, int> prognosed = GetPrognosedData(date); if(today) { foreach (KeyValuePair<DateTime, int> kv in present) { wd.StepIt(); chart1.Series["seriesPresent"].Points.AddXY(kv.Key, kv.Value); } } foreach (KeyValuePair<DateTime, int> kv in prognosed) { wd.StepIt(); chart1.Series["seriesPrognosed"].Points.AddXY(kv.Key, kv.Value); } wd.Close(); */ Logger.Leave(); }
private static void ChartOnPostPaint(object sender, ChartPaintEventArgs chartPaintEventArgs) { // Subscribing to PostPaint allows us to get the correct // bounds of the chart to send to the user. Some other events // don't seem to be sufficient. Chart ptrChart = sender as Chart; if (ptrChart == null) return; ptrChart.PostPaint -= ChartOnPostPaint; // Only run once OnZoomChanged(ptrChart); }
private void chart_PostPaint(object sender, ChartPaintEventArgs e) { if (ChartPostPaint != null) ChartPostPaint(this, EventArgs.Empty); }
private void lineChart_PostPaint(object sender, ChartPaintEventArgs e) { if (lineChart.Series.Count < 2) throw new RangeSpliceChartHelperException("Not enough series (need at least two)"); if(lineChart.Series[0].ChartType != SeriesChartType.Line) throw new RangeSpliceChartHelperException("Series[0] is not a line! (Series[0], the Top Line, needs to be a line)"); if (lineChart.Series[1].ChartType != SeriesChartType.Line) throw new RangeSpliceChartHelperException("Series[1] is not a line! (Series[1], the Bottom Line, needs to be a line)"); this.DrawPolygons(e.ChartGraphics, lineChart.Series[0], lineChart.Series[1]); }
void NetworkChart_PostPaint( object sender, ChartPaintEventArgs e ) { if ( RangeSelectEnd - RangeSelectStart <= 0 ) { return; } if ( e.ChartGraphics.Graphics != null && e.ChartElement is ChartArea && e.Chart.Series.Count > 0 && e.Chart.Series[0].Points.Count > 0 ) { ChartGraphics cg = e.ChartGraphics; System.Drawing.PointF Pos1 = System.Drawing.PointF.Empty; Pos1.X = ( float )cg.GetPositionFromAxis( "DefaultChartArea", AxisName.X, RangeSelectStart ); Pos1.Y = ( float )cg.GetPositionFromAxis( "DefaultChartArea", AxisName.Y, ( float )NetworkChart.ChartAreas["DefaultChartArea"].AxisY.Minimum ); System.Drawing.PointF Pos2 = System.Drawing.PointF.Empty; Pos2.X = ( float )cg.GetPositionFromAxis( "DefaultChartArea", AxisName.X, RangeSelectEnd ); Pos2.Y = ( float )cg.GetPositionFromAxis( "DefaultChartArea", AxisName.Y, NetworkChart.ChartAreas["DefaultChartArea"].AxisY.Maximum ); // Convert relative coordinates to absolute coordinates. Pos1 = cg.GetAbsolutePoint( Pos1 ); Pos2 = cg.GetAbsolutePoint( Pos2 ); SolidBrush Brush = new SolidBrush( Color.FromArgb( 20, 255, 0, 0 ) ); cg.Graphics.FillRectangle ( Brush, Pos1.X, Pos2.Y, Pos2.X - Pos1.X, Pos1.Y - Pos2.Y ); } }