public static void Run() { //ExStart:UsingWorkBookChartcellAsDatalabel // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); string lbl0 = "Label 0 cell value"; string lbl1 = "Label 1 cell value"; string lbl2 = "Label 2 cell value"; // Instantiate Presentation class that represents a presentation file using (Presentation pres = new Presentation(dataDir + "chart2.pptx")) { ISlide slide = pres.Slides[0]; IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Bubble, 50, 50, 600, 400, true); IChartSeriesCollection series = chart.ChartData.Series; series[0].Labels.DefaultDataLabelFormat.ShowLabelValueFromCell = true; IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; series[0].Labels[0].ValueFromCell = wb.GetCell(0, "A10", lbl0); series[0].Labels[1].ValueFromCell = wb.GetCell(0, "A11", lbl1); series[0].Labels[2].ValueFromCell = wb.GetCell(0, "A12", lbl2); pres.Save(path + "resultchart.pptx", Aspose.Slides.Export.SaveFormat.Pptx); } //ExEnd:UsingWorkBookChartcellAsDatalabel }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Create an instance of Presentation class Presentation presentation = new Presentation(); ISlide slide = presentation.Slides[0]; // Creating the default chart IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 0, 0, 400, 400); // Getting the default chart data worksheet index int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Delete demo series chart.ChartData.Series.Clear(); // Add new series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type); // Set the picture System.Drawing.Image image1 = (System.Drawing.Image) new Bitmap(dataDir + "aspose-logo.jpg"); IPPImage imgx1 = presentation.Images.AddImage(image1); // Set the picture System.Drawing.Image image2 = (System.Drawing.Image) new Bitmap(dataDir + "Tulips.jpg"); IPPImage imgx2 = presentation.Images.AddImage(image2); // Take first chart series IChartSeries series = chart.ChartData.Series[0]; // Add new point (1:3) there. IChartDataPoint point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, (double)4.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx1; point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, (double)2.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx2; point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, (double)3.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx1; point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 4, 1, (double)4.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx2; // Changing the chart series marker series.Marker.Size = 15; // Write presentation to disk presentation.Save(dataDir + "MarkOptions_out.pptx", SaveFormat.Pptx); }
public static void Run() { //ExStart:SettingDateFormatForCategoryAxis // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation()) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Area, 50, 50, 450, 300); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; wb.Clear(0); chart.ChartData.Categories.Clear(); chart.ChartData.Series.Clear(); chart.ChartData.Categories.Add(wb.GetCell(0, "A2", new DateTime(2015, 1, 1).ToOADate())); chart.ChartData.Categories.Add(wb.GetCell(0, "A3", new DateTime(2016, 1, 1).ToOADate())); chart.ChartData.Categories.Add(wb.GetCell(0, "A4", new DateTime(2017, 1, 1).ToOADate())); chart.ChartData.Categories.Add(wb.GetCell(0, "A5", new DateTime(2018, 1, 1).ToOADate())); IChartSeries series = chart.ChartData.Series.Add(ChartType.Line); series.DataPoints.AddDataPointForLineSeries(wb.GetCell(0, "B2", 1)); series.DataPoints.AddDataPointForLineSeries(wb.GetCell(0, "B3", 2)); series.DataPoints.AddDataPointForLineSeries(wb.GetCell(0, "B4", 3)); series.DataPoints.AddDataPointForLineSeries(wb.GetCell(0, "B5", 4)); chart.Axes.HorizontalAxis.CategoryAxisType = CategoryAxisType.Date; chart.Axes.HorizontalAxis.IsNumberFormatLinkedToSource = false; chart.Axes.HorizontalAxis.NumberFormat = "yyyy"; pres.Save(dataDir + "test.pptx", SaveFormat.Pptx); } //ExEnd:SettingDateFormatForCategoryAxis }
public static void Run() { LoadOptions loadOptions = new LoadOptions(); // Set preferred culture information for calculating some functions intended for use with languages // that use the double-byte character set (DBCS). loadOptions.SpreadsheetOptions.PreferredCulture = new System.Globalization.CultureInfo("ja-JP"); using (Presentation presentation = new Presentation(loadOptions)) { IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 150, 150, 500, 300); IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook; var cell = workbook.GetCell(0, "B2"); // Use the Formula property of the IChartDataCell interface to write a formula in a cell. cell.Formula = "FINDB(\"ス\", \"テキスト\")"; //Check calculation. if (Int32.Parse(cell.Value.ToString()) == 5) { Console.WriteLine("Calculated value = 5."); } else { Console.WriteLine("Wrong calculation!"); } } }
public static void Run() { //ExStart:SetInvertFillColorChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); Color inverColor = Color.Red; using (Presentation pres = new Presentation()) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 400, 300); IChartDataWorkbook workBook = chart.ChartData.ChartDataWorkbook; chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); // Adding new series and categories chart.ChartData.Series.Add(workBook.GetCell(0, 0, 1, "Series 1"), chart.Type); chart.ChartData.Categories.Add(workBook.GetCell(0, 1, 0, "Category 1")); chart.ChartData.Categories.Add(workBook.GetCell(0, 2, 0, "Category 2")); chart.ChartData.Categories.Add(workBook.GetCell(0, 3, 0, "Category 3")); // Take first chart series and populating series data. IChartSeries series = chart.ChartData.Series[0]; series.DataPoints.AddDataPointForBarSeries(workBook.GetCell(0, 1, 1, -20)); series.DataPoints.AddDataPointForBarSeries(workBook.GetCell(0, 2, 1, 50)); series.DataPoints.AddDataPointForBarSeries(workBook.GetCell(0, 3, 1, -30)); var seriesColor = series.GetAutomaticSeriesColor(); series.InvertIfNegative = true; series.Format.Fill.FillType = FillType.Solid; series.Format.Fill.SolidFillColor.Color = seriesColor; series.InvertedSolidFillColor.Color = inverColor; pres.Save(dataDir + "SetInvertFillColorChart_out.pptx", SaveFormat.Pptx); //ExEnd:SetInvertFillColorChart } }
public static void Run() { string outpptxFile = Path.Combine(RunExamples.OutPath, "ChartDataCell_Formulas_out.pptx"); using (Presentation presentation = new Presentation()) { IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 150, 150, 500, 300); IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook; IChartDataCell cell1 = workbook.GetCell(0, "B2"); cell1.Formula = "1 + SUM(F2:H5)"; IChartDataCell cell2 = workbook.GetCell(0, "C2"); cell2.R1C1Formula = "MAX(R2C6:R5C8) / 3"; presentation.Save(outpptxFile, SaveFormat.Pptx); } }
// This example demonstrates creating Map charts. // Please pay attension that when you first open a presentation in PP it may take a few seconds to upload an image // of the chart from the Bing service since we don't provide cached image. public static void Run() { string resultPath = Path.Combine(RunExamples.OutPath, "MapChart_out.pptx"); using (Presentation presentation = new Presentation()) { //create empty chart IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.Map, 50, 50, 500, 400, false); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; //Add series and few data points IChartSeries series = chart.ChartData.Series.Add(ChartType.Map); series.DataPoints.AddDataPointForMapSeries(wb.GetCell(0, "B2", 5)); series.DataPoints.AddDataPointForMapSeries(wb.GetCell(0, "B3", 1)); series.DataPoints.AddDataPointForMapSeries(wb.GetCell(0, "B4", 10)); //add categories chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "United States")); chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Mexico")); chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Brazil")); //change data point value IChartDataPoint dataPoint = series.DataPoints[1]; dataPoint.ColorValue.AsCell.Value = "15"; //set data point appearance dataPoint.Format.Fill.FillType = FillType.Solid; dataPoint.Format.Fill.SolidFillColor.Color = Color.Green; presentation.Save(resultPath, SaveFormat.Pptx); } }
public void Index() { using (Presentation pres = new Presentation()) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Histogram, 50, 50, 500, 400); chart.ChartData.Categories.Clear(); chart.ChartData.Series.Clear(); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; wb.Clear(0); IChartSeries series = chart.ChartData.Series.Add(ChartType.Histogram); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A1", 15)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A2", -41)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A3", 16)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A4", 10)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A5", -23)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A6", 16)); chart.Axes.HorizontalAxis.AggregationType = AxisAggregationType.Automatic; pres.Save("C:/Users/esshreem/Histogram.pptx", SaveFormat.Pptx); } }
//ExStart:HistogramChart public static void Run() { string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Histogram, 50, 50, 500, 400); chart.ChartData.Categories.Clear(); chart.ChartData.Series.Clear(); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; wb.Clear(0); IChartSeries series = chart.ChartData.Series.Add(ChartType.Histogram); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A1", 15)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A2", -41)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A3", 16)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A4", 10)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A5", -23)); series.DataPoints.AddDataPointForHistogramSeries(wb.GetCell(0, "A6", 16)); chart.Axes.HorizontalAxis.AggregationType = AxisAggregationType.Automatic; pres.Save(dataDir + "Histogram.pptx", SaveFormat.Pptx); } }
public static void Run() { //ExStart:SettingAutomicPieChartSliceColors // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Instantiate Presentation class that represents PPTX file using (Presentation presentation = new Presentation()) { // Instantiate Presentation class that represents PPTX file Presentation presentation = new Presentation(); // Access first slide ISlide slides = presentation.Slides[0]; // Add chart with default data IChart chart = slides.Shapes.AddChart(ChartType.Pie, 100, 100, 400, 400); // Setting chart Title chart.ChartTitle.AddTextFrameForOverriding("Sample Title"); chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True; chart.ChartTitle.Height = 20; chart.HasTitle = true; // Set first series to Show Values chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true; // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Delete default generated series and categories chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); // Adding new categories chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "First Qtr")); chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "2nd Qtr")); chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "3rd Qtr")); // Adding new series IChartSeries series = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type); // Now populating series data series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)); series.ParentSeriesGroup.IsColorVaried = true; presentation.Save("C:\\Aspose Data\\Pie.pptx", Aspose.Slides.Export.SaveFormat.Pptx); } }
/// <summary> /// Fills data chart from the secondary planFact table /// </summary> static void FillPlanFact(Presentation pres, DataRow row, DataTable planFactTable) { IChart chart = pres.Slides[0].Shapes[3] as Chart; IChartTitle chartTitle = chart.ChartTitle; chartTitle.TextFrameForOverriding.Text = row["Name"] + " : Plan / Fact"; DataRow[] selRows = planFactTable.Select("UserId = " + row["Id"]); string range = chart.ChartData.GetRange(); IChartDataWorkbook cellsFactory = chart.ChartData.ChartDataWorkbook; int worksheetIndex = 0; chart.ChartData.Series[0].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 1, 1, double.Parse(selRows[0]["PlanData"].ToString()))); chart.ChartData.Series[1].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 1, 2, double.Parse(selRows[0]["FactData"].ToString()))); chart.ChartData.Series[0].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 2, 1, double.Parse(selRows[1]["PlanData"].ToString()))); chart.ChartData.Series[1].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 2, 2, double.Parse(selRows[1]["FactData"].ToString()))); chart.ChartData.Series[0].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 3, 1, double.Parse(selRows[2]["PlanData"].ToString()))); chart.ChartData.Series[1].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 3, 2, double.Parse(selRows[2]["FactData"].ToString()))); chart.ChartData.Series[0].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 3, 1, double.Parse(selRows[3]["PlanData"].ToString()))); chart.ChartData.Series[1].DataPoints.AddDataPointForLineSeries( cellsFactory.GetCell(worksheetIndex, 3, 2, double.Parse(selRows[3]["FactData"].ToString()))); chart.ChartData.SetRange(range); }
//ExStart:FunnelChart public static void Run() { string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Funnel, 50, 50, 500, 400); chart.ChartData.Categories.Clear(); chart.ChartData.Series.Clear(); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; wb.Clear(0); chart.ChartData.Categories.Add(wb.GetCell(0, "A1", "Category 1")); chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "Category 2")); chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Category 3")); chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Category 4")); chart.ChartData.Categories.Add(wb.GetCell(0, "A5", "Category 5")); chart.ChartData.Categories.Add(wb.GetCell(0, "A6", "Category 6")); IChartSeries series = chart.ChartData.Series.Add(ChartType.Funnel); series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B1", 50)); series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B2", 100)); series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B3", 200)); series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B4", 300)); series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B5", 400)); series.DataPoints.AddDataPointForFunnelSeries(wb.GetCell(0, "B6", 500)); pres.Save(dataDir + "Funnel.pptx", SaveFormat.Pptx); } }
public static void Run() { //ExStart:PieChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Instantiate Presentation class that represents PPTX file Presentation presentation = new Presentation(); // Access first slide ISlide slides = presentation.Slides[0]; // Add chart with default data IChart chart = slides.Shapes.AddChart(ChartType.Pie, 100, 100, 400, 400); // Setting chart Title chart.ChartTitle.AddTextFrameForOverriding("Sample Title"); chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True; chart.ChartTitle.Height = 20; chart.HasTitle = true; // Set first series to Show Values chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true; // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Delete default generated series and categories chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); // Adding new categories chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "First Qtr")); chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "2nd Qtr")); chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "3rd Qtr")); // Adding new series IChartSeries series = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type); // Now populating series data series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)); // Not working in new version // Adding new points and setting sector color // series.IsColorVaried = true; chart.ChartData.SeriesGroups[0].IsColorVaried = true; IChartDataPoint point = series.DataPoints[0]; point.Format.Fill.FillType = FillType.Solid; point.Format.Fill.SolidFillColor.Color = Color.Cyan; // Setting Sector border point.Format.Line.FillFormat.FillType = FillType.Solid; point.Format.Line.FillFormat.SolidFillColor.Color = Color.Gray; point.Format.Line.Width = 3.0; point.Format.Line.Style = LineStyle.ThinThick; point.Format.Line.DashStyle = LineDashStyle.DashDot; IChartDataPoint point1 = series.DataPoints[1]; point1.Format.Fill.FillType = FillType.Solid; point1.Format.Fill.SolidFillColor.Color = Color.Brown; // Setting Sector border point1.Format.Line.FillFormat.FillType = FillType.Solid; point1.Format.Line.FillFormat.SolidFillColor.Color = Color.Blue; point1.Format.Line.Width = 3.0; point1.Format.Line.Style = LineStyle.Single; point1.Format.Line.DashStyle = LineDashStyle.LargeDashDot; IChartDataPoint point2 = series.DataPoints[2]; point2.Format.Fill.FillType = FillType.Solid; point2.Format.Fill.SolidFillColor.Color = Color.Coral; // Setting Sector border point2.Format.Line.FillFormat.FillType = FillType.Solid; point2.Format.Line.FillFormat.SolidFillColor.Color = Color.Red; point2.Format.Line.Width = 2.0; point2.Format.Line.Style = LineStyle.ThinThin; point2.Format.Line.DashStyle = LineDashStyle.LargeDashDotDot; // Create custom labels for each of categories for new series IDataLabel lbl1 = series.DataPoints[0].Label; // lbl.ShowCategoryName = true; lbl1.DataLabelFormat.ShowValue = true; IDataLabel lbl2 = series.DataPoints[1].Label; lbl2.DataLabelFormat.ShowValue = true; lbl2.DataLabelFormat.ShowLegendKey = true; lbl2.DataLabelFormat.ShowPercentage = true; IDataLabel lbl3 = series.DataPoints[2].Label; lbl3.DataLabelFormat.ShowSeriesName = true; lbl3.DataLabelFormat.ShowPercentage = true; // Showing Leader Lines for Chart series.Labels.DefaultDataLabelFormat.ShowLeaderLines = true; // Setting Rotation Angle for Pie Chart Sectors chart.ChartData.SeriesGroups[0].FirstSliceAngle = 180; // Save presentation with chart presentation.Save(dataDir + "PieChart_out.pptx", SaveFormat.Pptx); //ExEnd:PieChart }
//ExStart:BoxChart public static void Run() { string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.BoxAndWhisker, 50, 50, 500, 400); chart.ChartData.Categories.Clear(); chart.ChartData.Series.Clear(); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; wb.Clear(0); chart.ChartData.Categories.Add(wb.GetCell(0, "A1", "Category 1")); chart.ChartData.Categories.Add(wb.GetCell(0, "A2", "Category 1")); chart.ChartData.Categories.Add(wb.GetCell(0, "A3", "Category 1")); chart.ChartData.Categories.Add(wb.GetCell(0, "A4", "Category 1")); chart.ChartData.Categories.Add(wb.GetCell(0, "A5", "Category 1")); chart.ChartData.Categories.Add(wb.GetCell(0, "A6", "Category 1")); IChartSeries series = chart.ChartData.Series.Add(ChartType.BoxAndWhisker); series.QuartileMethod = QuartileMethodType.Exclusive; series.ShowMeanLine = true; series.ShowMeanMarkers = true; series.ShowInnerPoints = true; series.ShowOutlierPoints = true; series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B1", 15)); series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B2", 41)); series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B3", 16)); series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B4", 10)); series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B5", 23)); series.DataPoints.AddDataPointForBoxAndWhiskerSeries(wb.GetCell(0, "B6", 16)); pres.Save("BoxAndWhisker.pptx", SaveFormat.Pptx); } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Create an instance of Presentation class Presentation presentation = new Presentation(); // Get reference of the slide ISlide slide = presentation.Slides[0]; // Add PercentsStackedColumn chart on a slide IChart chart = slide.Shapes.AddChart(ChartType.PercentsStackedColumn, 20, 20, 500, 400); // Set NumberFormatLinkedToSource to false chart.Axes.VerticalAxis.IsNumberFormatLinkedToSource = false; chart.Axes.VerticalAxis.NumberFormat = "0.00%"; chart.ChartData.Series.Clear(); int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook; // Add new series IChartSeries series = chart.ChartData.Series.Add(workbook.GetCell(defaultWorksheetIndex, 0, 1, "Reds"), chart.Type); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 1, 1, 0.30)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 2, 1, 0.50)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 3, 1, 0.80)); series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 4, 1, 0.65)); // Setting the fill color of series series.Format.Fill.FillType = FillType.Solid; series.Format.Fill.SolidFillColor.Color = Color.Red; // Setting LabelFormat properties series.Labels.DefaultDataLabelFormat.ShowValue = true; series.Labels.DefaultDataLabelFormat.IsNumberFormatLinkedToSource = false; series.Labels.DefaultDataLabelFormat.NumberFormat = "0.0%"; series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FontHeight = 10; series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid; series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.White; series.Labels.DefaultDataLabelFormat.ShowValue = true; // Add new series IChartSeries series2 = chart.ChartData.Series.Add(workbook.GetCell(defaultWorksheetIndex, 0, 2, "Blues"), chart.Type); series2.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 1, 2, 0.70)); series2.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 2, 2, 0.50)); series2.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 3, 2, 0.20)); series2.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 4, 2, 0.35)); // Setting Fill type and color series2.Format.Fill.FillType = FillType.Solid; series2.Format.Fill.SolidFillColor.Color = Color.Blue; series2.Labels.DefaultDataLabelFormat.ShowValue = true; series2.Labels.DefaultDataLabelFormat.IsNumberFormatLinkedToSource = false; series2.Labels.DefaultDataLabelFormat.NumberFormat = "0.0%"; series2.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FontHeight = 10; series2.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid; series2.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.White; // Write presentation to disk presentation.Save(dataDir + "SetDataLabelsPercentageSign_out.pptx", SaveFormat.Pptx); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } Presentation pres = new Presentation(); ISlide slide = pres.Slides[0]; //Creating the default chart IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400); //Getting the default chart data worksheet index int defaultWorksheetIndex = 0; //Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; //Delete demo series chart.ChartData.Series.Clear(); //Add new series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type); chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type); //Take first chart series IChartSeries series = chart.ChartData.Series[0]; //Add new point (1:3) there. series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 1), fact.GetCell(defaultWorksheetIndex, 2, 2, 3)); //Add new point (2:10) series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 2), fact.GetCell(defaultWorksheetIndex, 3, 2, 10)); //Edit the type of series series.Type = ChartType.ScatterWithStraightLinesAndMarkers; //Changing the chart series marker series.Marker.Size = 10; series.Marker.Symbol = MarkerStyleType.Star; //Take second chart series series = chart.ChartData.Series[1]; //Add new point (5:2) there. series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 5), fact.GetCell(defaultWorksheetIndex, 2, 4, 2)); //Add new point (3:1) series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 3), fact.GetCell(defaultWorksheetIndex, 3, 4, 1)); //Add new point (2:2) series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 4, 3, 2), fact.GetCell(defaultWorksheetIndex, 4, 4, 2)); //Add new point (5:1) series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 5, 3, 5), fact.GetCell(defaultWorksheetIndex, 5, 4, 1)); //Changing the chart series marker series.Marker.Size = 10; series.Marker.Symbol = MarkerStyleType.Circle; pres.Save(dataDir + "AsposeChart.pptx", SaveFormat.Pptx); }
public static void Run() { //ExStart:ChartMarkerOptionsOnDataPoint string dataDir = RunExamples.GetDataDir_Charts(); Presentation pres = new Presentation(dataDir + "Test.pptx"); ISlide slide = pres.Slides[0]; //Creating the default chart IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 0, 0, 400, 400); //Getting the default chart data worksheet index int defaultWorksheetIndex = 0; //Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; //Delete demo series chart.ChartData.Series.Clear(); //Add new series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type); String imagePath = @"C:\Users\Public\Pictures\Sample Pictures\"; //Set the picture System.Drawing.Image img = (System.Drawing.Image) new Bitmap(imagePath + "Desert.jpg"); IPPImage imgx1 = pres.Images.AddImage(img); //Set the picture System.Drawing.Image img2 = (System.Drawing.Image) new Bitmap(imagePath + "Tulips.jpg"); IPPImage imgx2 = pres.Images.AddImage(img2); //Take first chart series IChartSeries series = chart.ChartData.Series[0]; //Add new point (1:3) there. IChartDataPoint point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, (double)4.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx1; point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, (double)2.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx2; point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, (double)3.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx1; point = series.DataPoints.AddDataPointForLineSeries(fact.GetCell(defaultWorksheetIndex, 4, 1, (double)4.5)); point.Marker.Format.Fill.FillType = FillType.Picture; point.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx2; //Changing the chart series marker series.Marker.Size = 15; pres.Save(dataDir + "AsposeScatterChart.pptx", SaveFormat.Pptx); }
public static void Run() { //ExStart:ExistingChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Instantiate Presentation class that represents PPTX file// Instantiate Presentation class that represents PPTX file Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); // Access first slideMarker ISlide sld = pres.Slides[0]; // Add chart with default data IChart chart = (IChart)sld.Shapes[0]; // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Changing chart Category Name fact.GetCell(defaultWorksheetIndex, 1, 0, "Modified Category 1"); fact.GetCell(defaultWorksheetIndex, 2, 0, "Modified Category 2"); // Take first chart series IChartSeries series = chart.ChartData.Series[0]; // Now updating series data fact.GetCell(defaultWorksheetIndex, 0, 1, "New_Series1");// Modifying series name series.DataPoints[0].Value.Data = 90; series.DataPoints[1].Value.Data = 123; series.DataPoints[2].Value.Data = 44; // Take Second chart series series = chart.ChartData.Series[1]; // Now updating series data fact.GetCell(defaultWorksheetIndex, 0, 2, "New_Series2");// Modifying series name series.DataPoints[0].Value.Data = 23; series.DataPoints[1].Value.Data = 67; series.DataPoints[2].Value.Data = 99; // Now, Adding a new series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.Type); // Take 3rd chart series series = chart.ChartData.Series[2]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 3, 20)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 50)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 30)); chart.Type = ChartType.ClusteredCylinder; // Save presentation with chart pres.Save(dataDir + "AsposeChartModified_out.pptx", SaveFormat.Pptx); //ExEnd:ExistingChart }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Create an instance of Presentation class Presentation presentation = new Presentation(); // Access first slide ISlide slide = presentation.Slides[0]; // Add chart with default data IChart chart = slide.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500); // Set first series to Show Values chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true; // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Delete default generated series and categories chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); int s = chart.ChartData.Series.Count; s = chart.ChartData.Categories.Count; // Adding new series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type); chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type); // Adding new categories chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); // Take first chart series IChartSeries series = chart.ChartData.Series[0]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)); // Setting automatic fill color for series series.Format.Fill.FillType = FillType.NotDefined; // Take second chart series series = chart.ChartData.Series[1]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60)); // Setting fill color for series series.Format.Fill.FillType = FillType.Solid; series.Format.Fill.SolidFillColor.Color = Color.Gray; // Save presentation with chart presentation.Save(dataDir + "AutomaticColor_out.pptx", SaveFormat.Pptx); }
public static void Run() { //ExStart:SettingCalloutForDataLabel string dataDir = RunExamples.GetDataDir_Charts(); Presentation pres = new Presentation(dataDir + "testc.pptx"); ISlide slide = pres.Slides[0]; IChart chart = slide.Shapes.AddChart(ChartType.Doughnut, 10, 10, 500, 500, false); IChartDataWorkbook workBook = chart.ChartData.ChartDataWorkbook; chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); chart.HasLegend = false; int seriesIndex = 0; while (seriesIndex < 15) { IChartSeries series = chart.ChartData.Series.Add(workBook.GetCell(0, 0, seriesIndex + 1, "SERIES " + seriesIndex), chart.Type); series.Explosion = 0; series.ParentSeriesGroup.DoughnutHoleSize = (byte)20; series.ParentSeriesGroup.FirstSliceAngle = 351; seriesIndex++; } int categoryIndex = 0; while (categoryIndex < 15) { chart.ChartData.Categories.Add(workBook.GetCell(0, categoryIndex + 1, 0, "CATEGORY " + categoryIndex)); int i = 0; while (i < chart.ChartData.Series.Count) { IChartSeries iCS = chart.ChartData.Series[i]; IChartDataPoint dataPoint = iCS.DataPoints.AddDataPointForDoughnutSeries(workBook.GetCell(0, categoryIndex + 1, i + 1, 1)); dataPoint.Format.Fill.FillType = FillType.Solid; dataPoint.Format.Line.FillFormat.FillType = FillType.Solid; dataPoint.Format.Line.FillFormat.SolidFillColor.Color = Color.White; dataPoint.Format.Line.Width = 1; dataPoint.Format.Line.Style = LineStyle.Single; dataPoint.Format.Line.DashStyle = LineDashStyle.Solid; if (i == chart.ChartData.Series.Count - 1) { IDataLabel lbl = dataPoint.Label; lbl.TextFormat.TextBlockFormat.AutofitType = TextAutofitType.Shape; lbl.DataLabelFormat.TextFormat.PortionFormat.FontBold = NullableBool.True; lbl.DataLabelFormat.TextFormat.PortionFormat.LatinFont = new FontData("DINPro-Bold"); lbl.DataLabelFormat.TextFormat.PortionFormat.FontHeight = 12; lbl.DataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid; lbl.DataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.LightGray; lbl.DataLabelFormat.Format.Line.FillFormat.SolidFillColor.Color = Color.White; lbl.DataLabelFormat.ShowValue = false; lbl.DataLabelFormat.ShowCategoryName = true; lbl.DataLabelFormat.ShowSeriesName = false; //lbl.DataLabelFormat.ShowLabelAsDataCallout = true; lbl.DataLabelFormat.ShowLeaderLines = true; lbl.DataLabelFormat.ShowLabelAsDataCallout = false; chart.ValidateChartLayout(); lbl.AsILayoutable.X = (float)lbl.AsILayoutable.X + (float)0.5; lbl.AsILayoutable.Y = (float)lbl.AsILayoutable.Y + (float)0.5; } i++; } categoryIndex++; } pres.Save("chart.pptx", Aspose.Slides.Export.SaveFormat.Pptx); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } // Instantiate Presentation class that represents PPTX file Presentation pres = new Presentation(); // Access first slide ISlide sld = pres.Slides[0]; // Add chart with default data IChart chart = sld.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500); // Setting chart Title // Chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title"; chart.ChartTitle.AddTextFrameForOverriding("Sample Title"); chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True; chart.ChartTitle.Height = 20; chart.HasTitle = true; // Set first series to Show Values chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true; // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Delete default generated series and categories chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); int s = chart.ChartData.Series.Count; s = chart.ChartData.Categories.Count; // Adding new series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type); chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type); // Adding new categories chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); // Take first chart series IChartSeries series = chart.ChartData.Series[0]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)); // Setting fill color for series series.Format.Fill.FillType = FillType.Solid; series.Format.Fill.SolidFillColor.Color = Color.Red; // Take second chart series series = chart.ChartData.Series[1]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60)); // Setting fill color for series series.Format.Fill.FillType = FillType.Solid; series.Format.Fill.SolidFillColor.Color = Color.Green; // First label will be show Category name IDataLabel lbl = series.DataPoints[0].Label; lbl.DataLabelFormat.ShowCategoryName = true; lbl = series.DataPoints[1].Label; lbl.DataLabelFormat.ShowSeriesName = true; // Show value for third label lbl = series.DataPoints[2].Label; lbl.DataLabelFormat.ShowValue = true; lbl.DataLabelFormat.ShowSeriesName = true; lbl.DataLabelFormat.Separator = "/"; // Save presentation with chart pres.Save(dataDir + "AsposeChart_out.pptx", SaveFormat.Pptx); }
public static void Run() { //ExStart:MultiCategoryChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); Presentation pres = new Presentation(); ISlide slide = pres.Slides[0]; IChart ch = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 600, 450); ch.ChartData.Series.Clear(); ch.ChartData.Categories.Clear(); IChartDataWorkbook fact = ch.ChartData.ChartDataWorkbook; fact.Clear(0); int defaultWorksheetIndex = 0; IChartCategory category = ch.ChartData.Categories.Add(fact.GetCell(0, "c2", "A")); category.GroupingLevels.SetGroupingItem(1, "Group1"); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c3", "B")); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c4", "C")); category.GroupingLevels.SetGroupingItem(1, "Group2"); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c5", "D")); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c6", "E")); category.GroupingLevels.SetGroupingItem(1, "Group3"); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c7", "F")); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c8", "G")); category.GroupingLevels.SetGroupingItem(1, "Group4"); category = ch.ChartData.Categories.Add(fact.GetCell(0, "c9", "H")); // Adding Series IChartSeries series = ch.ChartData.Series.Add(fact.GetCell(0, "D1", "Series 1"), ChartType.ClusteredColumn); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D2", 10)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D3", 20)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D4", 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D5", 40)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D6", 50)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D7", 60)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D8", 70)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, "D9", 80)); // Save presentation with chart pres.Save(dataDir + "AsposeChart_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx); //ExEnd:MultiCategoryChart }
public static void Run() { //ExStart:SupportForStockChart string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "Test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.OpenHighLowClose, 50, 50, 600, 400, false); chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; chart.ChartData.Categories.Add(wb.GetCell(0, 1, 0, "A")); chart.ChartData.Categories.Add(wb.GetCell(0, 2, 0, "B")); chart.ChartData.Categories.Add(wb.GetCell(0, 3, 0, "C")); chart.ChartData.Series.Add(wb.GetCell(0, 0, 1, "Open"), chart.Type); chart.ChartData.Series.Add(wb.GetCell(0, 0, 2, "High"), chart.Type); chart.ChartData.Series.Add(wb.GetCell(0, 0, 3, "Low"), chart.Type); chart.ChartData.Series.Add(wb.GetCell(0, 0, 4, "Close"), chart.Type); IChartSeries series = chart.ChartData.Series[0]; series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 1, 72)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 1, 25)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 1, 38)); series = chart.ChartData.Series[1]; series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 2, 172)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 2, 57)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 2, 57)); series = chart.ChartData.Series[2]; series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 3, 12)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 3, 12)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 3, 13)); series = chart.ChartData.Series[3]; series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 1, 4, 25)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 2, 4, 38)); series.DataPoints.AddDataPointForStockSeries(wb.GetCell(0, 3, 4, 50)); chart.ChartData.SeriesGroups[0].UpDownBars.HasUpDownBars = true; chart.ChartData.SeriesGroups[0].HiLowLinesFormat.Line.FillFormat.FillType = FillType.Solid; foreach (IChartSeries ser in chart.ChartData.Series) { ser.Format.Line.FillFormat.FillType = FillType.NoFill; } pres.Save(dataDir + "output.pptx", SaveFormat.Pptx); } }
//ExStart:SunburstChart public static void Run() { string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Sunburst, 50, 50, 500, 400); chart.ChartData.Categories.Clear(); chart.ChartData.Series.Clear(); IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; wb.Clear(0); //branch 1 IChartCategory leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C1", "Leaf1")); leaf.GroupingLevels.SetGroupingItem(1, "Stem1"); leaf.GroupingLevels.SetGroupingItem(2, "Branch1"); chart.ChartData.Categories.Add(wb.GetCell(0, "C2", "Leaf2")); leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C3", "Leaf3")); leaf.GroupingLevels.SetGroupingItem(1, "Stem2"); chart.ChartData.Categories.Add(wb.GetCell(0, "C4", "Leaf4")); //branch 2 leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C5", "Leaf5")); leaf.GroupingLevels.SetGroupingItem(1, "Stem3"); leaf.GroupingLevels.SetGroupingItem(2, "Branch2"); chart.ChartData.Categories.Add(wb.GetCell(0, "C6", "Leaf6")); leaf = chart.ChartData.Categories.Add(wb.GetCell(0, "C7", "Leaf7")); leaf.GroupingLevels.SetGroupingItem(1, "Stem4"); chart.ChartData.Categories.Add(wb.GetCell(0, "C8", "Leaf8")); IChartSeries series = chart.ChartData.Series.Add(ChartType.Sunburst); series.Labels.DefaultDataLabelFormat.ShowCategoryName = true; series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D1", 4)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D2", 5)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D3", 3)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D4", 6)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D5", 9)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D6", 9)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D7", 4)); series.DataPoints.AddDataPointForSunburstSeries(wb.GetCell(0, "D8", 3)); pres.Save("Sunburst.pptx", SaveFormat.Pptx); } }
public static void Run() { string outPath = Path.Combine(RunExamples.OutPath, "RadarChart_Out.pptx"); using (Presentation pres = new Presentation()) { // Access first slide ISlide sld = pres.Slides[0]; // Add Radar chart IChart ichart = sld.Shapes.AddChart(ChartType.Radar, 0, 0, 400, 400); // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data WorkSheet IChartDataWorkbook fact = ichart.ChartData.ChartDataWorkbook; // Set chart title ichart.ChartTitle.AddTextFrameForOverriding("Radar Chart"); // Delete default generated series and categories ichart.ChartData.Categories.Clear(); ichart.ChartData.Series.Clear(); // Adding new categories ichart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); ichart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 3")); ichart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 5")); ichart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 4, 0, "Caetegoty 7")); ichart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 5, 0, "Caetegoty 9")); ichart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 6, 0, "Caetegoty 11")); // Adding new series ichart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), ichart.Type); ichart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), ichart.Type); // Now populating series data IChartSeries series = ichart.ChartData.Series[0]; series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 2.7)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 2.4)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 1.5)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 4, 1, 3.5)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 5, 1, 5)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 6, 1, 3.5)); // Set series color series.Format.Line.FillFormat.FillType = FillType.Solid; series.Format.Line.FillFormat.SolidFillColor.Color = Color.DarkRed; // Now populating another series data series = ichart.ChartData.Series[1]; series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 2.5)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 2.4)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 1.6)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 4, 2, 3.5)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 5, 2, 4)); series.DataPoints.AddDataPointForRadarSeries(fact.GetCell(defaultWorksheetIndex, 6, 2, 3.6)); // Set series color series.Format.Line.FillFormat.FillType = FillType.Solid; series.Format.Line.FillFormat.SolidFillColor.Color = Color.Orange; // Set legend position ichart.Legend.Position = LegendPositionType.Bottom; // Setting Category Axis Text Properties IChartPortionFormat txtCat = ichart.Axes.HorizontalAxis.TextFormat.PortionFormat; txtCat.FontBold = NullableBool.True; txtCat.FontHeight = 10; txtCat.FillFormat.FillType = FillType.Solid;; txtCat.FillFormat.SolidFillColor.Color = Color.DimGray; txtCat.LatinFont = new FontData("Calibri"); // Setting Legends Text Properties IChartPortionFormat txtleg = ichart.Legend.TextFormat.PortionFormat; txtleg.FontBold = NullableBool.True; txtleg.FontHeight = 10; txtleg.FillFormat.FillType = FillType.Solid;; txtleg.FillFormat.SolidFillColor.Color = Color.DimGray; txtCat.LatinFont = new FontData("Calibri"); // Setting Value Axis Text Properties IChartPortionFormat txtVal = ichart.Axes.VerticalAxis.TextFormat.PortionFormat; txtVal.FontBold = NullableBool.True; txtVal.FontHeight = 10; txtVal.FillFormat.FillType = FillType.Solid;; txtVal.FillFormat.SolidFillColor.Color = Color.DimGray; txtVal.LatinFont = new FontData("Calibri"); // Setting value axis number format ichart.Axes.VerticalAxis.IsNumberFormatLinkedToSource = false; ichart.Axes.VerticalAxis.NumberFormat = "\"$\"#,##0.00"; // Setting chart major unit value ichart.Axes.VerticalAxis.IsAutomaticMajorUnit = false; ichart.Axes.VerticalAxis.MajorUnit = 1.25f; // Save generated presentation pres.Save(outPath, SaveFormat.Pptx); } }
public static void Run() { //ExStart:SetGapWidth // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Creating empty presentation Presentation presentation = new Presentation(); // Access first slide ISlide slide = presentation.Slides[0]; // Add chart with default data IChart chart = slide.Shapes.AddChart(ChartType.StackedColumn, 0, 0, 500, 500); // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Add series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type); chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type); // Add Catrgories chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); // Take second chart series IChartSeries series = chart.ChartData.Series[1]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60)); // Set GapWidth value series.ParentSeriesGroup.GapWidth = 50; // Save presentation with chart presentation.Save(dataDir + "GapWidth_out.pptx", SaveFormat.Pptx); //ExEnd:SetGapWidth }
public static void add3DPieChartToSlide(ISlide slide, ChartProperty chartProperty, Dictionary <string, decimal> data) { string title = chartProperty.title; float x = chartProperty.x; float y = chartProperty.y; float height = chartProperty.height; float width = chartProperty.width; IChart chart = slide.Shapes.AddChart(ChartType.Pie3D, x, y, width, height); // Setting chart Title chart.ChartTitle.AddTextFrameForOverriding(title); chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True; chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.WrapText = NullableBool.False; chart.ChartTitle.Height = 30; chart.HasTitle = true; int defaultWorksheetIndex = 0; int index = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Delete default generated series and categories chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); // Adding new series IChartSeries series = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, title), chart.Type); //chart.ChartData.SeriesGroups[0].IsColorVaried = true; var sortedData = from objDic in data orderby objDic.Value descending select objDic; var sum = sortedData.Select(item => item.Value).Sum(); foreach (KeyValuePair <string, decimal> pair in sortedData) { // Adding new categories double percent = (double)(pair.Value / sum); string percentStr = percent.ToString("0.%"); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, index, 0, pair.Key + ":" + percentStr)); // Now populating series data series.DataPoints.AddDataPointForPieSeries(fact.GetCell(defaultWorksheetIndex, index, 1, pair.Value)); index++; } // Create custom labels for each of categories for new series for (int i = 0; i < series.DataPoints.Count; i++) { Color dataPointColor = getDataPointColorByIndex(i); series.DataPoints[i].Format.Fill.FillType = FillType.Solid; series.DataPoints[i].Format.Fill.SolidFillColor.Color = dataPointColor; IDataLabel lbl = series.DataPoints[i].Label; lbl.TextFrameForOverriding.TextFrameFormat.WrapText = NullableBool.False; lbl.DataLabelFormat.Position = LegendDataLabelPosition.InsideEnd; lbl.DataLabelFormat.ShowCategoryName = false; lbl.DataLabelFormat.ShowPercentage = true; lbl.DataLabelFormat.ShowLeaderLines = false; lbl.DataLabelFormat.Separator = ","; } // no showing Legend key in chart series.Chart.HasLegend = true; // Set Legend Properties chart.Legend.Width = 350 / chart.Width; chart.Legend.Height = 60 / chart.Height; // Showing Leader Lines for Chart series.Labels.DefaultDataLabelFormat.ShowLeaderLines = false; series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black; series.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid; chart.Legend.Position = LegendPositionType.Bottom; }
public static void Run() { //ExStart:ManagePropertiesCharts // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Create an instance of Presentation class Presentation presentation = new Presentation(); // Access first slide ISlide slide = presentation.Slides[0]; // Add chart with default data IChart chart = slide.Shapes.AddChart(ChartType.StackedColumn3D, 0, 0, 500, 500); // Setting the index of chart data sheet int defaultWorksheetIndex = 0; // Getting the chart data worksheet IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; // Add series chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type); chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type); // Add Catrgories chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); // Set Rotation3D properties chart.Rotation3D.RightAngleAxes = true; chart.Rotation3D.RotationX = 40; chart.Rotation3D.RotationY = 270; chart.Rotation3D.DepthPercents = 150; // Take second chart series IChartSeries series = chart.ChartData.Series[1]; // Now populating series data series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10)); series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60)); // Set OverLap value series.ParentSeriesGroup.Overlap = 100; // Write presentation to disk presentation.Save(dataDir + "Rotation3D_out.pptx", SaveFormat.Pptx); //ExEnd:ManagePropertiesCharts }
public static void Run() { //ExStart:DefaultMarkersInChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation()) { ISlide slide = pres.Slides[0]; IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 10, 10, 400, 400); chart.ChartData.Series.Clear(); chart.ChartData.Categories.Clear(); IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type); IChartSeries series = chart.ChartData.Series[0]; chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "C1")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 1, 1, 24)); chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "C2")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 2, 1, 23)); chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "C3")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 3, 1, -10)); chart.ChartData.Categories.Add(fact.GetCell(0, 4, 0, "C4")); series.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 4, 1, null)); chart.ChartData.Series.Add(fact.GetCell(0, 0, 2, "Series 2"), chart.Type); //Take second chart series IChartSeries series2 = chart.ChartData.Series[1]; //Now populating series data series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 1, 2, 30)); series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 2, 2, 10)); series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 3, 2, 60)); series2.DataPoints.AddDataPointForLineSeries(fact.GetCell(0, 4, 2, 40)); chart.HasLegend = true; chart.Legend.Overlay = false; pres.Save(dataDir + "DefaultMarkersInChart.pptx", SaveFormat.Pptx); } //ExEnd:DefaultMarkersInChart }