//////////////////////////////////////////////////////////////////// // Draw Pie Chart //////////////////////////////////////////////////////////////////// public void DrawPieChart() { // create Chart object Chart PieChart = PdfChart.CreateChart(Document, 6.5, 4.0, 300.0); // create PdfChart object PdfChart PiePdfChart = new PdfChart(Document, PieChart); PiePdfChart.SaveAs = SaveImageAs.IndexedImage; // make sure we have good quality image PieChart.AntiAliasing = AntiAliasingStyles.None; //.All; // set colors PieChart.BackColor = Color.FromArgb(220, 220, 255); PieChart.Palette = ChartColorPalette.BrightPastel; // title (font size is 0.25 inches) Font TitleFont1 = PiePdfChart.CreateFont("Verdana", FontStyle.Bold, 0.25, FontSizeUnit.UserUnit); Title Title1 = new Title("Pie Chart Example", Docking.Top, TitleFont1, Color.Purple); PieChart.Titles.Add(Title1); // title (font size is 0.25 inches) Font TitleFont2 = PiePdfChart.CreateFont("Verdana", FontStyle.Bold, 0.15, FontSizeUnit.UserUnit); Title Title2 = new Title("Percent Fruit Sales", Docking.Top, TitleFont2, Color.Purple); PieChart.Titles.Add(Title2); // default font Font DefaultFont = PiePdfChart.CreateFont("Verdana", FontStyle.Regular, 0.12, FontSizeUnit.UserUnit); // legend Legend Legend1 = new Legend(); PieChart.Legends.Add(Legend1); Legend1.BackColor = Color.FromArgb(230, 230, 255); Legend1.Docking = Docking.Bottom; Legend1.Font = DefaultFont; // chart area ChartArea ChartArea1 = new ChartArea(); PieChart.ChartAreas.Add(ChartArea1); // chart area background color ChartArea1.BackColor = Color.FromArgb(255, 200, 255); // series 1 Series Series1 = new Series(); PieChart.Series.Add(Series1); Series1.ChartType = SeriesChartType.Pie; Series1.Font = DefaultFont; Series1.IsValueShownAsLabel = true; Series1.LabelFormat = "{0} %"; // series values Series1.Points.Add(20.0); Series1.Points[0].LegendText = "Apple"; Series1.Points.Add(25.0); Series1.Points[1].LegendText = "Banana"; Series1.Points.Add(10.0); Series1.Points[2].LegendText = "Pear"; Series1.Points.Add(30.0); Series1.Points[3].LegendText = "Orange"; Series1.Points.Add(15.0); Series1.Points[4].LegendText = "Grape"; // draw chart into page contents Contents.DrawChart(PiePdfChart, 1.0, 6.0); return; }
//////////////////////////////////////////////////////////////////// // Draw chart //////////////////////////////////////////////////////////////////// private void DrawChart() { // save graphics state Contents.SaveGraphicsState(); // create chart Chart PieChart = PdfChart.CreateChart(Document, 1.8, 1.5, 300.0); // create PdfChart object with Chart object PdfImageControl ImageControl = new PdfImageControl(); ImageControl.SaveAs = SaveImageAs.IndexedImage; PdfChart PiePdfChart = new PdfChart(Document, PieChart, ImageControl); // make sure we have good quality image PieChart.AntiAliasing = AntiAliasingStyles.None; //.All; // set colors PieChart.BackColor = Color.FromArgb(220, 220, 255); PieChart.Palette = ChartColorPalette.BrightPastel; // default font Font DefaultFont = PiePdfChart.CreateFont("Verdana", FontStyle.Regular, 0.05, FontSizeUnit.UserUnit); Font TitleFont = PiePdfChart.CreateFont("Verdana", FontStyle.Bold, 0.07, FontSizeUnit.UserUnit); // title (font size is 0.25 inches) Title Title1 = new Title("Pie Chart Example", Docking.Top, TitleFont, Color.Purple); PieChart.Titles.Add(Title1); // legend Legend Legend1 = new Legend(); PieChart.Legends.Add(Legend1); Legend1.BackColor = Color.FromArgb(230, 230, 255); Legend1.Docking = Docking.Bottom; Legend1.Font = DefaultFont; // chart area ChartArea ChartArea1 = new ChartArea(); PieChart.ChartAreas.Add(ChartArea1); // chart area background color ChartArea1.BackColor = Color.FromArgb(255, 200, 255); // series 1 Series Series1 = new Series(); PieChart.Series.Add(Series1); Series1.ChartType = SeriesChartType.Pie; Series1.Font = DefaultFont; Series1.IsValueShownAsLabel = true; Series1.LabelFormat = "{0} %"; // series values Series1.Points.Add(22.0); Series1.Points[0].LegendText = "Apple"; Series1.Points.Add(27.0); Series1.Points[1].LegendText = "Banana"; Series1.Points.Add(33.0); Series1.Points[2].LegendText = "Orange"; Series1.Points.Add(18.0); Series1.Points[3].LegendText = "Grape"; Contents.DrawChart(PiePdfChart, 5.6, 5.0); // restore graphics state Contents.RestoreGraphicsState(); return; }