Ejemplo n.º 1
0
        /// <summary>
        /// Draw the Chart.
        /// </summary>
        public virtual void GenerateChart()
        {
            var xAxis = _xAxis1;
            var yAxis = _yAxis;

            CalculateInitialLayout();

            xAxis.FinaliseAxisLayout(xAxis.AxisCoords, yAxis.AxisCoords);
            yAxis.FinaliseAxisLayout(xAxis.AxisCoords, yAxis.AxisCoords);
            CalculateDataPointLabelDimensions();

            if ((ChartLegend.LegendEntries.Count == 0) && (ChartLegend.IsLegendVisible))
            {
                AutoGenerateLegendEntries();
            }
            CalculateLegendDimensions();

            SizeF chartDimension = GetChartDimensions();

            Bitmap bmp = new Bitmap((int)chartDimension.Width, (int)chartDimension.Height);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.Clear(ImageBackgroundColor);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                DrawBorder(g);

                DrawTitles(g);

                xAxis.DrawAxis(g, bmp, xAxis.AxisPosition, xAxis.GetDimensions().Width, yAxis.GetDimensions().Height);
                yAxis.DrawAxis(g, bmp, xAxis.AxisPosition, xAxis.GetDimensions().Width, yAxis.GetDimensions().Height);

                /*Pen rectPen = new Pen(Brushes.Red, 1);
                 * rectPen.DashPattern = new float[] { 10, 10 };
                 * ImageMethods.Debug_DrawRectangle(g, new Rectangle(xAxis.AxisCoords, xAxis.GetDimensions()), rectPen);
                 * ImageMethods.Debug_DrawRectangle(g, new Rectangle(yAxis.AxisCoords, yAxis.GetDimensions()), rectPen);*/

                PlotData(g);

                if (ChartLegend.IsLegendVisible)
                {
                    Bitmap legendBMP = DrawLegend();

                    int xOffset = bmp.Width;
                    xOffset -= GetMargin(ElementPosition.RIGHT) + GetPadding(ElementPosition.RIGHT);
                    if (BorderPen != null)
                    {
                        xOffset -= (int)BorderPen.Width;
                    }
                    xOffset -= legendBMP.Width;

                    int yOffset = GetMargin(ElementPosition.TOP) + GetPadding(ElementPosition.TOP);
                    if (BorderPen != null)
                    {
                        yOffset += (int)BorderPen.Width;
                    }

                    ImageMethods.CopyRegionIntoImage(legendBMP, new Rectangle(0, 0, legendBMP.Width, legendBMP.Height),
                                                     ref bmp, new Rectangle(xOffset,
                                                                            yOffset, legendBMP.Width, legendBMP.Height));
                }
            }

            bmp.Save(OutputFile, ImageFormat.Png);
        }