//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 void ChartWithDataTableAsSeriesSource() { var table = new DataTable(); table.Columns.Add("x", typeof(double)); table.Columns.Add("y", typeof(double)); table.Rows.Add(2.5, 33.3); table.Rows.Add(0.5, 13.3); // create chart and add function as a data source using object adapter class FunctionSeriesDataSource //IChart chart = new Chart(); IChartSeries series = ChartSeriesFactory.CreateLineSeries(); series.DataSource = table; series.XValuesDataMember = "x"; series.YValuesDataMember = "y"; var chartView1 = new ChartView(); chartView1.Chart.Series.Add(series); var form = new Form { Width = 600, Height = 100 }; form.Controls.Add(chartView1); WindowsFormsTestHelper.ShowModal(form); }
public void ChartWithObjectsAsSeriesSource() { IList objects = new ArrayList { new { X = 2.5, Y = 33.3 }, new { X = 0.5, Y = 13.3 } }; // create chart and add function as a data source using object adapter class FunctionSeriesDataSource IChartSeries series = ChartSeriesFactory.CreateLineSeries(); series.DataSource = objects; series.XValuesDataMember = "X"; series.YValuesDataMember = "Y"; var chartView1 = new ChartView(); chartView1.Chart.Series.Add(series); // show form var form = new Form { Width = 600, Height = 100 }; form.Controls.Add(chartView1); WindowsFormsTestHelper.ShowModal(form); }
public static void Run() { //ExStart:SupportForSwitchingRowsAndColumns string dataDir = RunExamples.GetDataDir_Charts(); using (Presentation pres = new Presentation(dataDir + "Test.pptx")) { IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 400, 300); IChartSeries[] series = new IChartSeries[chart.ChartData.Series.Count]; chart.ChartData.Series.CopyTo(series, 0); IChartDataCell[] categoriesCells = new IChartDataCell[chart.ChartData.Categories.Count]; for (int i = 0; i < chart.ChartData.Categories.Count; i++) { categoriesCells[i] = chart.ChartData.Categories[i].AsCell; } IChartDataCell[] seriesCells = new IChartDataCell[chart.ChartData.Series.Count]; for (int i = 0; i < chart.ChartData.Series.Count; i++) { seriesCells[i] = chart.ChartData.Series[i].Name.AsCells[0]; } chart.ChartData.SwitchRowColumn(); pres.Save(RunExamples.OutPath + "Test_out.pptx", SaveFormat.Pptx); //ExEnd:SupportForSwitchingRowsAndColumns } }
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); }
// 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() { string dataDir = RunExamples.GetDataDir_Charts(); //ExStart:SetChartDataFromWorkBook pres = new Presentation(dataDir + "Test.pptx"); IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Pie, 50, 50, 500, 400); chart.ChartData.ChartDataWorkbook.Clear(0); Workbook workbook = null; try { workbook = new Aspose.Cells.Workbook("a1.xlsx"); } catch (Exception ex) { Console.Write(ex); } MemoryStream mem = new MemoryStream(); workbook.Save(mem, Aspose.Cells.SaveFormat.Xlsx); chart.ChartData.WriteWorkbookStream(mem); chart.ChartData.SetRange("Sheet1!$A$1:$B$9"); IChartSeries series = chart.ChartData.Series[0]; series.ParentSeriesGroup.IsColorVaried = true; pres.Save(dataDir + "response2.pptx", SaveFormat.Pptx); //ExEnd:SetChartDataFromWorkBook }
internal void AddSeries(IChartSeries series) { if (!Series.Contains(series)) { Series.Add(series); } }
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 void ChangeYMemberSeriesViewWithFunctionAsDataSource() { var function = new Function(); var Y = new Variable <double>("Y"); var Z = new Variable <double>("Z"); var n = new Variable <double>("n"); function.Arguments.Add(Y); function.Components.Add(Z); function.Components.Add(n); Y.SetValues(new[] { 0.0, 3.0, 5.0, 6.0, 7.0 }); Z.SetValues(new[] { 0.0, 10.0, 15.0, 21.0, 15.0 }); n.SetValues(new[] { 0.001, 0.001, 0.01, 0.01, 0.01 }); var chartView = new ChartView(); IChartSeries series = ChartSeriesFactory.CreateLineSeries(); series.XValuesDataMember = Y.DisplayName; series.YValuesDataMember = Z.DisplayName; series.DataSource = new FunctionBindingList(function) { SynchronizeInvoke = chartView }; chartView.Chart.Series.Add(series); WindowsFormsTestHelper.ShowModal(chartView); }
public static void Run() { // ExStart:CustomRotationAngleTextframe // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Text(); // ExStart:CustomRotationAngleTextframe // Create an instance of Presentation class Presentation presentation = new Presentation(); IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.ClusteredColumn, 50, 50, 500, 300); IChartSeries series = chart.ChartData.Series[0]; series.Labels.DefaultDataLabelFormat.ShowValue = true; series.Labels.DefaultDataLabelFormat.TextFormat.TextBlockFormat.RotationAngle = 65; chart.HasTitle = true; chart.ChartTitle.AddTextFrameForOverriding("Custom title").TextFrameFormat.RotationAngle = -30; // ExEnd:CustomRotationAngleTextframe // Save Presentation presentation.Save(dataDir + "textframe-rotation_out.pptx", SaveFormat.Pptx); // ExEnd:CustomRotationAngleTextframe }
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 } }
/// <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: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: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() { // 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]; IChart chart = slide.Shapes.AddChart(ChartType.StackedColumn, 20, 20, 400, 400); IChartSeries series = chart.ChartData.Series[0]; IChartCategory cat; double[] total_for_Cat = new double[chart.ChartData.Categories.Count]; for (int k = 0; k < chart.ChartData.Categories.Count; k++) { cat = chart.ChartData.Categories[k]; for (int i = 0; i < chart.ChartData.Series.Count; i++) { total_for_Cat[k] = total_for_Cat[k] + Convert.ToDouble(chart.ChartData.Series[i].DataPoints[k].Value.Data); } } double dataPontPercent = 0f; for (int x = 0; x < chart.ChartData.Series.Count; x++) { series = chart.ChartData.Series[x]; series.Labels.DefaultDataLabelFormat.ShowLegendKey = false; for (int j = 0; j < series.DataPoints.Count; j++) { IDataLabel lbl = series.DataPoints[j].Label; dataPontPercent = (Convert.ToDouble(series.DataPoints[j].Value.Data) / total_for_Cat[j]) * 100; IPortion port = new Portion(); port.Text = String.Format("{0:F2} %", dataPontPercent); port.PortionFormat.FontHeight = 8f; lbl.TextFrameForOverriding.Text = ""; IParagraph para = lbl.TextFrameForOverriding.Paragraphs[0]; para.Portions.Add(port); lbl.DataLabelFormat.ShowSeriesName = false; lbl.DataLabelFormat.ShowPercentage = false; lbl.DataLabelFormat.ShowLegendKey = false; lbl.DataLabelFormat.ShowCategoryName = false; lbl.DataLabelFormat.ShowBubbleSize = false; } } // Save presentation with chart presentation.Save(dataDir + "DisplayPercentageAsLabels_out.pptx", SaveFormat.Pptx); }
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: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: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: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; }
private void NotifySelectionChanged() { if (!this.IsTreeLoaded) { return; } IChartSeries series = this.Presenter as IChartSeries; if (series != null) { series.OnDataPointIsSelectedChanged(this); } }
public void MultipleSeriesExtraAxesView() { IChart chart = CreateMultipleSeriesChart(); IChartSeries chartSeries = chart.Series[0]; chartSeries.HorizAxis = HorizontalAxis.Top; chartSeries.VertAxis = VerticalAxis.Right; IChartView chartView = new ChartView { Chart = chart }; WindowsFormsTestHelper windowsFormsTestHelper = new WindowsFormsTestHelper(); windowsFormsTestHelper.ShowControlModal((ChartView)chartView); }
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:HideInformationFromChart // 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, 140, 118, 320, 370); //Hiding chart Title chart.HasTitle = false; ///Hiding Values axis chart.Axes.VerticalAxis.IsVisible = false; //Category Axis visibility chart.Axes.HorizontalAxis.IsVisible = false; //Hiding Legend chart.HasLegend = false; //Hiding MajorGridLines chart.Axes.HorizontalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill; for (int i = 0; i < chart.ChartData.Series.Count; i++) { chart.ChartData.Series.RemoveAt(i); } IChartSeries series = chart.ChartData.Series[0]; series.Marker.Symbol = MarkerStyleType.Circle; series.Labels.DefaultDataLabelFormat.ShowValue = true; series.Labels.DefaultDataLabelFormat.Position = LegendDataLabelPosition.Top; series.Marker.Size = 15; //Setting series line color series.Format.Line.FillFormat.FillType = FillType.Solid; series.Format.Line.FillFormat.SolidFillColor.Color = Color.Purple; series.Format.Line.DashStyle = LineDashStyle.Solid; pres.Save(dataDir + "HideInformationFromChart.pptx", SaveFormat.Pptx); } //ExEnd:HideInformationFromChart }
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 void ChangeYMemberSeriesView() { ChartView chartView = new ChartView(); IChartSeries series = ChartSeriesFactory.CreateLineSeries(); series.DataSource = InitTable(); series.XValuesDataMember = "Y"; series.YValuesDataMember = "Z"; chartView.Chart.Series.Add(series); series.YValuesDataMember = "n"; series.CheckDataSource(); WindowsFormsTestHelper windowsFormsTestHelper = new WindowsFormsTestHelper(); windowsFormsTestHelper.ShowControlModal(chartView); }
public static void Run() { //ExStart:AddCustomError // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Charts(); // Creating empty presentation using (Presentation presentation = new Presentation()) { // Creating a bubble chart IChart chart = presentation.Slides[0].Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, true); // Adding custom Error bars and setting its format IChartSeries series = chart.ChartData.Series[0]; IErrorBarsFormat errBarX = series.ErrorBarsXFormat; IErrorBarsFormat errBarY = series.ErrorBarsYFormat; errBarX.IsVisible = true; errBarY.IsVisible = true; errBarX.ValueType = ErrorBarValueType.Custom; errBarY.ValueType = ErrorBarValueType.Custom; // Accessing chart series data point and setting error bars values for individual point IChartDataPointCollection points = series.DataPoints; points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXPlusValues = DataSourceType.DoubleLiterals; points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXMinusValues = DataSourceType.DoubleLiterals; points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYPlusValues = DataSourceType.DoubleLiterals; points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYMinusValues = DataSourceType.DoubleLiterals; // Setting error bars for chart series points for (int i = 0; i < points.Count; i++) { points[i].ErrorBarsCustomValues.XMinus.AsLiteralDouble = i + 1; points[i].ErrorBarsCustomValues.XPlus.AsLiteralDouble = i + 1; points[i].ErrorBarsCustomValues.YMinus.AsLiteralDouble = i + 1; points[i].ErrorBarsCustomValues.YPlus.AsLiteralDouble = i + 1; } // Saving presentation presentation.Save(dataDir + "ErrorBarsCustomValues_out.pptx", SaveFormat.Pptx); //ExEnd:AddCustomError } }
private static IDictionary<string, object> GetJson(IChartSeries series) { return series.CreateSerializer().Serialize(); }
public ChartSeriesSerializerBase(IChartSeries series) { this.series = series; }