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); } }
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 } }
// 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 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 }
/// <summary> /// 生成单列图表 /// </summary> /// <param name="sld">当前ppt页面</param> /// <param name="dt">数据</param> /// <param name="index">图表所属表格排序(当前slide)</param> public static void SingleAxexchart(ISlide sld, System.Data.DataTable dt, int index, Office_ChartStyle style) { IChart chart = (IChart)sld.Shapes[index]; string range = "Sheet1!$A$1:$" + Base_ColumnsHelper.GET_INDEX(dt.Columns.Count) + "$" + (dt.Rows.Count + 1); //实例化图表数据表 IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook; chart.ChartData.ChartDataWorkbook.Clear(0); Workbook workbook = Office_TableToWork.GetWorkBooxFromDataTable(dt); MemoryStream mem = new MemoryStream(); workbook.Save(mem, Aspose.Cells.SaveFormat.Xlsx); chart.ChartData.WriteWorkbookStream(mem); //设置数据区域 chart.ChartData.SetRange(range); //交换横纵坐标 if (style.坐标方向 == Base_Config.坐标方向.横向) { chart.ChartData.SwitchRowColumn(); } IChartSeries series = chart.ChartData.Series[0]; series.Labels.DefaultDataLabelFormat.ShowValue = style.是否显示文字; series.Labels.DefaultDataLabelFormat.Position = style.文字位置; series.Labels.DefaultDataLabelFormat.TextFormat.TextBlockFormat.TextVerticalType = style.文字旋转方向; }
//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); } }
//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() { 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: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:TreeMapChart public static void Run() { string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(Aspose.Slides.Charts.ChartType.Treemap, 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(Aspose.Slides.Charts.ChartType.Treemap); series.Labels.DefaultDataLabelFormat.ShowCategoryName = true; series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D1", 4)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D2", 5)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D3", 3)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D4", 6)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D5", 9)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D6", 9)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D7", 4)); series.DataPoints.AddDataPointForTreemapSeries(wb.GetCell(0, "D8", 3)); series.ParentLabelLayout = ParentLabelLayoutType.Overlapping; pres.Save("Treemap.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); } }
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: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 }
/// <summary> /// 供需分析图表 /// </summary> /// <param name="sld"></param> /// <param name="dt"></param> /// <param name="index"></param> /// <param name="fc"></param> /// <param name="sc"></param> public static void Chart_gxfx(ISlide sld, System.Data.DataTable dt, int index) { IChart t1 = (IChart)sld.Shapes[index]; string range = "Sheet1!$A$1:$" + Base_ColumnsHelper.GET_INDEX(dt.Columns.Count) + "$" + (dt.Rows.Count + 1); //实例化图表数据表 IChartDataWorkbook fact = t1.ChartData.ChartDataWorkbook; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMajorUnit = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMaxValue = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMinorUnit = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMinValue = true; t1.ChartData.ChartDataWorkbook.Clear(0); Workbook workbook = Office_TableToWork.GetWorkBooxFromDataTable(dt); MemoryStream mem = new MemoryStream(); workbook.Save(mem, Aspose.Cells.SaveFormat.Xlsx); t1.ChartData.WriteWorkbookStream(mem); t1.ChartData.SetRange(range); ///第一列 IChartSeries series = t1.ChartData.Series[0]; series.Type = ChartType.ClusteredColumn; series.Labels.DefaultDataLabelFormat.ShowValue = true; series.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.OutsideEnd; ///第二列 IChartSeries series1 = t1.ChartData.Series[1]; series1.Type = ChartType.ClusteredColumn; series1.Labels.DefaultDataLabelFormat.ShowValue = true; series1.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.OutsideEnd; ////设置第二个系列表 IChartSeries series2 = t1.ChartData.Series[2]; series2.PlotOnSecondAxis = true; series2.Type = ChartType.LineWithMarkers; series2.Type = ChartType.StackedLineWithMarkers; series2.Labels.DefaultDataLabelFormat.ShowValue = true; series2.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.Top; series2.Labels.DefaultDataLabelFormat.Format.Fill.FillType = FillType.Solid; series2.Labels.DefaultDataLabelFormat.Format.Fill.SolidFillColor.Color = System.Drawing.Color.White; series2.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.FillType = FillType.Solid; series2.Labels.DefaultDataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black; }
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 Chart_jp_langshi_chart1(ISlide sld, System.Data.DataTable dt, int index) { IChart t1 = (IChart)sld.Shapes[index]; string range = "Sheet1!$A$1:$" + Base_ColumnsHelper.GET_INDEX(dt.Columns.Count) + "$" + (dt.Rows.Count + 1); //实例化图表数据表 IChartDataWorkbook fact = t1.ChartData.ChartDataWorkbook; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMajorUnit = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMaxValue = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMinorUnit = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMinValue = true; t1.ChartData.ChartDataWorkbook.Clear(0); Workbook workbook = Office_TableToWork.GetWorkBooxFromDataTable(dt); MemoryStream mem = new MemoryStream(); workbook.Save(mem, Aspose.Cells.SaveFormat.Xlsx); t1.ChartData.WriteWorkbookStream(mem); t1.ChartData.SetRange(range); //交换横纵坐标 t1.ChartData.SwitchRowColumn(); //t1.ChartData.SwitchRowColumn(); ///第一列 IChartSeries series = t1.ChartData.Series[0]; series.Type = ChartType.ClusteredColumn; series.Labels.DefaultDataLabelFormat.ShowValue = true; series.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.InsideBase; series.Labels.DefaultDataLabelFormat.TextFormat.TextBlockFormat.TextVerticalType = TextVerticalType.Vertical270; ///第二列 IChartSeries series1 = t1.ChartData.Series[1]; series1.Type = ChartType.ClusteredColumn; series1.Labels.DefaultDataLabelFormat.ShowValue = true; series1.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.InsideBase; series1.Labels.DefaultDataLabelFormat.TextFormat.TextBlockFormat.TextVerticalType = TextVerticalType.Vertical270; IChartSeries series2 = t1.ChartData.Series[2]; series2.PlotOnSecondAxis = true; series2.Type = ChartType.StackedLineWithMarkers; series2.Labels.DefaultDataLabelFormat.ShowValue = true; series2.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.Top; }
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 }
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); } }
public static void Run() { string dataDir = RunExamples.GetDataDir_Charts(); string pptxFile = Path.Combine(dataDir, "ExternalWB.pptx"); string outPptxFile = Path.Combine(RunExamples.OutPath, "ExternalWB_out.pptx"); LoadOptions lo = new LoadOptions(); lo.SpreadsheetOptions.RecoverWorkbookFromChartCache = true; using (Presentation pres = new Presentation(pptxFile, lo)) { IChart chart = pres.Slides[0].Shapes[0] as IChart; IChartDataWorkbook wb = chart.ChartData.ChartDataWorkbook; pres.Save(outPptxFile, 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); }
/// <summary> /// 竞品复地--第一个图表 /// </summary> /// <param name="sld"></param> /// <param name="dt"></param> /// <param name="index"></param> public static void Chart_jp_fudi_chart1(ISlide sld, System.Data.DataTable dt, int index) { IChart t1 = (IChart)sld.Shapes[index]; dt = dt.AsEnumerable().OrderByDescending(m => m["成交套数"]).CopyToDataTable(); string range = "Sheet1!$A$1:$" + Base_ColumnsHelper.GET_INDEX(dt.Columns.Count) + "$" + (dt.Rows.Count + 1); //实例化图表数据表 IChartDataWorkbook fact = t1.ChartData.ChartDataWorkbook; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMajorUnit = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMaxValue = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMinorUnit = true; //t1.Axes.SecondaryVerticalAxis.IsAutomaticMinValue = true; t1.ChartData.ChartDataWorkbook.Clear(0); Workbook workbook = Office_TableToWork.GetWorkBooxFromDataTable(dt); MemoryStream mem = new MemoryStream(); workbook.Save(mem, Aspose.Cells.SaveFormat.Xlsx); t1.ChartData.WriteWorkbookStream(mem); t1.ChartData.SetRange(range); ///第一列 IChartSeries series = t1.ChartData.Series[0]; series.Type = ChartType.ClusteredColumn; series.Labels.DefaultDataLabelFormat.ShowValue = true; series.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.OutsideEnd; ///第二列 IChartSeries series1 = t1.ChartData.Series[1]; series1.PlotOnSecondAxis = true; series1.Type = ChartType.StackedLineWithMarkers; series1.Labels.DefaultDataLabelFormat.ShowValue = true; series1.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.Top; }
//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() { //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() { // 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: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 }
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() { // 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); }