/// <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.Web.UI.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 Chart1_PrePaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
 {
     if (e.ChartElement is Chart)
     {
         // Creare mini-chart inside each series
         if (Series2.SelectedItem.Value != "None")
         {
             // Position new chart areas with mini-chart over the data points
             PositionChartAreas(Chart1, Chart1.Series["Default"]);
         }
     }
 }
        protected void Chart1_PrePaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            //    foreach (Series charts in Chart1.Series)
            //    {
            //        foreach (DataPoint point in charts.Points)
            //        {

            //            point.Label = string.Format("{1}-{0:0} ",point.AxisLabel, point.YValues[0]);

            //        }
            //    }
        }
 /// <summary>
 /// Chart Paint event handler.
 /// </summary>
 private void Chart_PostPaint(object sender, System.Web.UI.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(sender, e);
         }
     }
 }
Beispiel #5
0
        private void Chart1_PostPaint(object sender, System.Web.UI.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);
                }
            }
        }
        protected void Chart3_PrePaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            if (e.ChartElement is System.Web.UI.DataVisualization.Charting.Series && ((System.Web.UI.DataVisualization.Charting.Series)e.ChartElement).Name == "Series1")
            {
                System.Web.UI.DataVisualization.Charting.Series        s  = e.Chart.Series[0];
                System.Web.UI.DataVisualization.Charting.ChartGraphics cg = e.ChartGraphics;

                // Highlight the maximum sales this year
                for (int i = 0; i < s.Points.Count; i++)
                {
                    string colour = StudentLogic.getCustomColour(float.Parse(s.Points[i].YValues[0].ToString()));

                    s.Points[i].Color = System.Drawing.ColorTranslator.FromHtml(colour);
                }
            }
        }
        protected void Chart1_PrePaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            if (e.ChartElement is System.Web.UI.DataVisualization.Charting.Series && ((System.Web.UI.DataVisualization.Charting.Series)e.ChartElement).Name == "Series1")
            {
                System.Web.UI.DataVisualization.Charting.Series        s  = e.Chart.Series[0];
                System.Web.UI.DataVisualization.Charting.ChartGraphics cg = e.ChartGraphics;
                double max = s.Points.FindMaxByValue().YValues[0];

                // Highlight the maximum sales this year
                for (int i = 0; i < s.Points.Count; i++)
                {
                    string colour = StudentLogic.getColourForResult(float.Parse(s.Points[i].YValues[0].ToString()));
                    s.Points[i].Color = System.Drawing.ColorTranslator.FromHtml(colour);
                    if (s.Points[i].XValue.Equals(Session["courseID"].ToString()))
                    {
                    }
                }
            }
        }
 protected void Chart8_PrePaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
 {
     Label42.BackColor = Chart5.Series["Series1"].Color;
     Label43.BackColor = Chart5.Series["Series2"].Color;
 }
 protected void Chart7_PrePaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
 {
 }
        //-------------------------------------------------------------------------------------------------------

        protected void Chart7_PostPaint(object sender, System.Web.UI.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            Label39.BackColor = Chart7.Series["Series1"].Color;
            Label40.BackColor = Chart7.Series["Series2"].Color;
        }
Beispiel #11
0
        private void Chart1_PrePaint(object sender, System.Web.UI.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 = 2;

                    // 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]);
                }
            }
        }
        /// <summary>
        /// This method does all the work for the painting of the data table.
        /// </summary>
        private void PaintDataTable(object sender, System.Web.UI.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;

            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(area.Name, AxisName.X, AxisValue);
                            float nextPixelX = (float)e.ChartGraphics.GetPositionFromAxis(area.Name, 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;
                    }
                }
            }
        }