Пример #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (series_list.Count == 0)
            {
                ChartTools.renderNoDatasetMessage(e.Graphics);
                return;
            }

            ChartRegion region_fullscreen = new ChartRegion(0, 0, this.Width, this.Height);

            ChartRegion region_title; ChartRegion region_title_remainder;

            region_fullscreen.splitHorizontal(title_height, out region_title, out region_title_remainder);

            ChartRegion region_legend; ChartRegion region_legend_remainder;

            region_title_remainder.splitHorizontal(region_title_remainder.Height - legend_height, out region_legend_remainder, out region_legend);
            region_legend.Top += 10;

            ChartRegion region_chart; ChartRegion region_x_axis; ChartRegion region_y1_axis; ChartRegion region_y2_axis;

            region_legend_remainder.splitAxes(axis_height, out region_chart, out region_x_axis, out region_y1_axis, out region_y2_axis);

            Point2D min_pri; Point2D max_pri; Point2D min_sec; Point2D max_sec;

            getSeriesExtents(out min_pri, out max_pri, out min_sec, out max_sec);

            // Set the axis overrides
            if (!double.IsNaN(x_axis_max))
            {
                max_pri.x = x_axis_max;
            }
            if (!double.IsNaN(x_axis_max))
            {
                max_sec.x = x_axis_max;
            }
            if (!double.IsNaN(x_axis_min))
            {
                min_pri.x = x_axis_min;
            }
            if (!double.IsNaN(x_axis_min))
            {
                min_sec.x = x_axis_min;
            }
            if (!double.IsNaN(y1_axis_max))
            {
                max_pri.y = y1_axis_max;
            }
            if (!double.IsNaN(y1_axis_min))
            {
                min_pri.y = y1_axis_min;
            }
            if (!double.IsNaN(y2_axis_max))
            {
                max_sec.y = y2_axis_max;
            }
            if (!double.IsNaN(y2_axis_min))
            {
                min_sec.y = y2_axis_min;
            }

            // Check that our series are beautifully coloured
            for (int i_series = 0; i_series < series_list.Count; ++i_series)
            {
                Series series = (Series)series_list[i_series];
                if (series.color == Color.Black)
                {
                    series.color = ChartColours.getOrderedColour(i_series);
                }
            }

            // Draw the various bits of the chart
            try
            {
                performPaintBackground(e.Graphics, region_chart);
                performPaintTitle(e.Graphics, region_title);
                performPaintLegend(e.Graphics, region_legend);

                if (region_chart.Height > 0 && region_chart.Width > 0)
                {
                    performPaintXAxis(e.Graphics, region_chart, region_x_axis, min_pri, max_pri);
                    performPaintY1Axis(e.Graphics, region_chart, region_y1_axis, min_pri, max_pri);
                    performPaintY2Axis(e.Graphics, region_chart, region_y2_axis, min_sec, max_sec);
                    performPaintSeries(e.Graphics, region_chart, min_pri, max_pri, min_sec, max_sec);
                }

                performPaintBorders(e.Graphics, region_chart);
            }

            catch (Exception)
            {
            }
        }
Пример #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // If we have a dataset to render
            if (null != dataset)
            {
                int datasetwidth  = dataset.GetUpperBound(1) + 1;
                int datasetheight = dataset.GetUpperBound(0) + 1;
                int screenwidth   = this.Width;
                int screenheight  = this.Height;

                float rendersquarewidth  = screenwidth / (float)datasetwidth;
                float rendersquareheight = screenheight / (float)datasetheight;

                // Check that the mouse is still in range
                if (last_mouse_x > screenwidth)
                {
                    last_mouse_x = screenwidth - 1;
                }
                if (last_mouse_y > screenheight)
                {
                    last_mouse_y = screenheight - 1;
                }

                SolidBrush brush = new SolidBrush(Color.Black);
                for (int i = 0; i < datasetheight; ++i)
                {
                    for (int j = 0; j < datasetwidth; ++j)
                    {
                        if (Double.IsNaN(dataset[i, j]))
                        {
                            brush.Color = Color.Orange;
                        }
                        else if (datasetmin == dataset[i, j])
                        {
                            brush.Color = Color.Blue;
                        }
                        else if (datasetmax == dataset[i, j])
                        {
                            brush.Color = Color.Red;
                        }
                        else
                        {
                            int colorvalue = 255 - (int)(255.0 * (dataset[i, j] - datasetmin) / (datasetmax - datasetmin));
                            brush.Color = Color.FromArgb(colorvalue, colorvalue, colorvalue);
                        }

                        e.Graphics.FillRectangle(brush, j * rendersquarewidth, i * rendersquareheight, rendersquarewidth, rendersquareheight);
                    }
                }

                // Print out some information
                double current_y = y_min + (y_max - y_min) * last_mouse_y / (double)(this.Height - rendersquareheight);
                double current_x = x_min + (x_max - x_min) * last_mouse_x / (double)(this.Width - rendersquarewidth);

                int dataset_i = (int)(datasetheight * last_mouse_y / (double)this.Height);
                int dataset_j = (int)(datasetwidth * last_mouse_x / (double)this.Width);
                if (dataset_i > dataset.GetUpperBound(0))
                {
                    dataset_i = dataset.GetUpperBound(0);
                }
                if (dataset_j > dataset.GetUpperBound(1))
                {
                    dataset_j = dataset.GetUpperBound(1);
                }
                if (dataset_i < 0)
                {
                    dataset_i = 0;
                }
                if (dataset_j < 0)
                {
                    dataset_j = 0;
                }

                Font font = new Font(FontFamily.GenericSansSerif, 8.0f);
                brush.Color = Color.Green;
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Mouse at {0}={1} {2}={3} value={4} i,j=({5},{6})", x_name, current_x, y_name, current_y, dataset[dataset_i, dataset_j], dataset_i, dataset_j);
                e.Graphics.DrawString(sb.ToString(), font, brush, 10, 10);
            }

            // Otherwise we have no dataset to render
            else
            {
                ChartTools.renderNoDatasetMessage(e.Graphics);
            }
        }