示例#1
0
        public Bitmap Show_MSChart()
        {
            try
            {
                if (!Check_Chart())
                    return null;

                ChartArea chartArea = new ChartArea("chartArea");
                Grid grid = new Grid();
                grid.LineDashStyle = ChartDashStyle.Solid;
                grid.LineColor = Color.Black;

                Legend lengend = new Legend();
                lengend.Docking = Docking.Right;

                chartArea.AxisX.MajorGrid = grid;
                chartArea.AxisY.MajorGrid = grid;
                chartArea.AxisX.Interval = 1;
                chartArea.AxisX.IsLabelAutoFit = false;
                chartArea.BackColor = Color.FromArgb(0xEF, 0xEF, 0xEF);

                Series series = new Series("危险度");
                series.ChartType = SeriesChartType.Column;
                //series.IsValueShownAsLabel = true;
                series.Color = dataColor;
                series.BorderWidth = 0;

                SmartLabelStyle smartLabelStyle = new SmartLabelStyle();
                smartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes;
                series.SmartLabelStyle = smartLabelStyle;

                series.Points.DataBindXY(dataTable.DefaultView, dataX, dataTable.DefaultView, dataY);
                Chart chart = new Chart();
                chart.Width = width;
                chart.Height = height;
                chart.ChartAreas.Add(chartArea);
                chart.Series.Add(series);
                chart.Legends.Add(lengend);

                MemoryStream memoryStream = new MemoryStream();
                chart.SaveImage(memoryStream, ChartImageFormat.Jpeg);

                Bitmap bitmap = new Bitmap(memoryStream);
                return bitmap;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
		private static void SetupGrid(Grid grid, GraphGridConfiguration configuration)
		{
			grid.Enabled   = configuration.Enabled;
			grid.LineWidth = configuration.LineWidth;
			grid.LineColor = configuration.LineColor;
		}