public override void Paint(PaintEventArgs pe) { if (PaintSelectionOnly(pe)) { base.Paint(pe); return; } pe.Graphics.FillRectangle(BackgroundBrush, Bounds); using (var nonScaledImage = new Bitmap(Bounds.Width, Bounds.Height)) { nonScaledImage.SetResolution(pe.Graphics.DpiX, pe.Graphics.DpiY); using (var chart = new System.Windows.Forms.DataVisualization.Charting.Chart { Dock = DockStyle.Fill, Size = Bounds.Size }) { var chartArea = new ChartArea("Main"); chart.ChartAreas.Add(chartArea); // Create series and add it to the chart var seriesColumns = new Series("RandomColumns"); // Add 10 random values to the series var random = new Random(0); for (int i = 0; i < 10; i++) { seriesColumns.Points.Add(random.Next(100)); } seriesColumns.ChartType = SeriesChartType.Radar; chart.Series.Add(seriesColumns); chart.DrawToBitmap(nonScaledImage, new Rectangle(Point.Empty, Bounds.Size)); } pe.Graphics.DrawImageUnscaled(nonScaledImage, Bounds.Location); } base.Paint(pe); }
private bool LoadPieChart(Chart pieChart, List<GeoSoft.Plugins.Interpolation.Classes.TempPIEChartData> pieChartData) { pieChart.Series.Clear(); pieChart.Palette = ChartColorPalette.Fire; pieChart.ChartAreas[0].BackColor = Color.Transparent; Series series1 = new Series { Name = "series1", IsVisibleInLegend = true, Color = System.Drawing.Color.Green, ChartType = SeriesChartType.Pie }; pieChart.Series.Add(series1); foreach (var item in pieChartData) { var p = series1.Points.Add(item.Count); p.Color = item.Color; } pieChart.Invalidate(); panelChart.Controls.Add(pieChart); Bitmap bmp = new Bitmap(panelChart.Width, panelChart.Height); pieChart.DrawToBitmap(bmp, panelChart.ClientRectangle); return true; }
ImageInfo IImageRenderer.Render(ILayoutArea layoutArea, string mimeType, SizeF dpi) { var reportItem = layoutArea.ReportItem; var customData = ((ICustomReportItem)reportItem).CustomData; if (customData == null) { return(new ImageInfo()); } if (customData.DataRowGroupings == null || customData.DataRowGroupings.Count != 1) { return(new ImageInfo()); } var values = new List <double>(customData.DataRowGroupings[0].Count); // read the values from nested data members foreach (DataMember member in customData.DataRowGroupings[0]) { double value; if (ReadValue(member, out value)) // we have to check that there is corresponding property to read series value { values.Add(value); } } var bounds = GetImageBounds(reportItem, layoutArea); if (dpi.IsEmpty) { dpi = new SizeF(Resolution.Width, Resolution.Height); } var imageSize = new Size(FromTwipsToPixels(bounds.Width, dpi.Width), FromTwipsToPixels(bounds.Height, dpi.Height)); if (imageSize.Width == 0 || imageSize.Height == 0) { return(new ImageInfo()); } using (var nonScaledImage = new Bitmap(imageSize.Width, imageSize.Height)) { nonScaledImage.SetResolution(dpi.Width, dpi.Height); using (var chart = new System.Windows.Forms.DataVisualization.Charting.Chart { Dock = DockStyle.Fill, Size = imageSize }) { var chartArea = new ChartArea("Main"); chart.ChartAreas.Add(chartArea); // Create series and add it to the chart var seriesColumns = new Series("Columns"); foreach (var val in values) { seriesColumns.Points.Add(Convert.ToDouble(val)); } seriesColumns.ChartType = SeriesChartType.Radar; chart.Series.Add(seriesColumns); chart.DrawToBitmap(nonScaledImage, new Rectangle(Point.Empty, imageSize)); } var stream = new MemoryStream(); nonScaledImage.Save(stream, ImageFormat.Png); stream.Flush(); stream.Position = 0; return(new ImageInfo(stream, "image/png")); } }