Package com.aspose.slides

Examples of com.aspose.slides.IChart


    //Access first slide
    ISlide sld = pres.getSlides().get_Item(0);

    // Add chart with default data
    IChart chart = (IChart)sld.getShapes().get_Item(0);

    //Setting the index of chart data sheet
    int defaultWorksheetIndex = 0;

    //Getting the chart data worksheet
    IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

    //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.getChartData().getSeries().get_Item(0);

    //Now updating series data
    fact.getCell(defaultWorksheetIndex, 0, 1, "New_Series1");//modifying series name
    series.getDataPoints().get_Item(0).getValue().setData (90);
    series.getDataPoints().get_Item(1).getValue().setData ( 123);
    series.getDataPoints().get_Item(2).getValue().setData ( 44);

    //Take Second chart series
    series = chart.getChartData().getSeries().get_Item(1);

    //Now updating series data
    fact.getCell(defaultWorksheetIndex, 0, 2, "New_Series2");//modifying series name
    series.getDataPoints().get_Item(0).getValue().setData (23);
    series.getDataPoints().get_Item(1).getValue().setData ( 67);
    series.getDataPoints().get_Item(2).getValue().setData ( 99);


    //Now, Adding a new series
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.getType());

    //Take 3rd chart series
    series = chart.getChartData().getSeries().get_Item(2);

    //Now populating series data
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 3, 20));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 50));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 30));

    chart.setType(ChartType.ClusteredCylinder);

    // Save presentation with chart
    pres.save("data/pptx4j/ChartModified-Aspose.pptx", SaveFormat.Pptx)
    System.out.println("Done");
  }
View Full Code Here


    //Access first slide
    ISlide sld = pres.getSlides().get_Item(0);

    // Add chart with default data
    IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

    //Setting chart Title
    //chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title";
    chart.getChartTitle().addTextFrameForOverriding("Sample Title");
    chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
    chart.getChartTitle().setHeight (20);
    chart.hasTitle(true);

    //Set first series to Show Values
    chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue( true);

    //Setting the index of chart data sheet
    int defaultWorksheetIndex = 0;

    //Getting the chart data worksheet
    IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

    //Delete default generated series and categories
    chart.getChartData().getSeries().clear();
    chart.getChartData().getCategories().clear();
    int s = chart.getChartData().getSeries().size();
    s = chart.getChartData().getCategories().size();

    //Adding new series
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType());
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType());

    //Adding new categories
    chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
    chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
    chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));

    //Take first chart series
    IChartSeries series = chart.getChartData().getSeries().get_Item(0);

    //Now populating series data

    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

    //Setting fill color for series
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor (Color.RED);


    //Take second chart series
    series = chart.getChartData().getSeries().get_Item(1);

    //Now populating series data
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));
View Full Code Here

    //Access first slide
    ISlide sld = pres.getSlides().get_Item(0);

    // Add chart with default data
    IChart chart = sld.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400);

    //Setting chart Title
    chart.getChartTitle().addTextFrameForOverriding("Sample Title");
    chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
    chart.getChartTitle().setHeight(20);
    chart.hasTitle(true);

    //Set first series to Show Values
    chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);

    //Setting the index of chart data sheet
    int defaultWorksheetIndex = 0;

    //Getting the chart data worksheet
    IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

    //Delete default generated series and categories

    chart.getChartData().getSeries().clear();
    chart.getChartData().getCategories().clear();

    //Adding new categories
    chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"));
    chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"));
    chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"));

    //Adding new series
    IChartSeries series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());

    //Now populating series data
    series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
    series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
    series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));


    //Not working in new version
    //Adding new points and setting sector color
    //series.IsColorVaried = true;
    chart.getChartData().getSeriesGroups().get_Item(0).isColorVaried(true);

    IChartDataPoint point = series.getDataPoints().get_Item(0);
    point.getFormat().getFill().setFillType(FillType.Solid);
    point.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN);
    //Setting Sector border
    point.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    point.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
    point.getFormat().getLine().setWidth(3.0);
    point.getFormat().getLine().setStyle(LineStyle.ThinThick);
    point.getFormat().getLine().setDashStyle(LineDashStyle.DashDot);


    IChartDataPoint point1 = series.getDataPoints().get_Item(1);
    point1.getFormat().getFill().setFillType (FillType.Solid);
    point1.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Brown));

    //Setting Sector border
    point1.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    point1.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    point1.getFormat().getLine().setWidth(3.0);
    point1.getFormat().getLine().setStyle(LineStyle.Single);
    point1.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot);

    IChartDataPoint point2 = series.getDataPoints().get_Item(2);
    point2.getFormat().getFill().setFillType(FillType.Solid);
    point2.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Coral));

    //Setting Sector border
    point2.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    point2.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
    point2.getFormat().getLine().setWidth(2.0);
    point2.getFormat().getLine().setStyle(LineStyle.ThinThin);
    point2.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot);


    //Create custom labels for each of categories for new series

    IDataLabel lbl1 = series.getDataPoints().get_Item(0).getLabel();
    // lbl.ShowCategoryName = true;
    lbl1.getDataLabelFormat().setShowValue(true);


    IDataLabel lbl2 = series.getDataPoints().get_Item(1).getLabel();
    lbl2.getDataLabelFormat().setShowValue (true);
    lbl2.getDataLabelFormat().setShowLegendKey(true);
    lbl2.getDataLabelFormat().setShowPercentage(true);

    IDataLabel lbl3 = series.getDataPoints().get_Item(2).getLabel();
    lbl3.getDataLabelFormat().setShowSeriesName(true);
    lbl3.getDataLabelFormat().setShowPercentage (true);


    //Showing Leader Lines for Chart
    series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true);

    //Setting Rotation Angle for Pie Chart Sectors
    chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180);

    // Save presentation with chart
    pres.save("data/AsposePieChart.pptx", SaveFormat.Pptx);
   
    System.out.println("Done");
View Full Code Here

    //Accessing the first slide
    ISlide slide = pres.getSlides().get_Item(0);

    //Adding the sample chart
    IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 50, 50, 500, 400);

    //Setting Chart Titile
    chart.hasTitle(true);
    chart.getChartTitle().addTextFrameForOverriding("");
    IPortion chartTitle = chart.getChartTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0);
    chartTitle.setText("Sample Chart");
    chartTitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    chartTitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
    chartTitle.getPortionFormat().setFontHeight (20);
    chartTitle.getPortionFormat().setFontBold(NullableBool.True);
    chartTitle.getPortionFormat().setFontItalic(NullableBool.True);

    //Setting Major grid lines format for value axis
    chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().setWidth(5);
    chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().setDashStyle(LineDashStyle.DashDot);

    //Setting Minor grid lines format for value axis
    chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
    chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().setWidth(3);

    //Setting value axis number format
    chart.getAxes().getVerticalAxis().isNumberFormatLinkedToSource(false);
    chart.getAxes().getVerticalAxis().setDisplayUnit(DisplayUnitType.Thousands);
    chart.getAxes().getVerticalAxis().setNumberFormat("0.0%");

    //Setting chart maximum, minimum values
    chart.getAxes().getVerticalAxis().isAutomaticMajorUnit(false);
    chart.getAxes().getVerticalAxis().isAutomaticMaxValue(false);
    chart.getAxes().getVerticalAxis().isAutomaticMinorUnit(false);
    chart.getAxes().getVerticalAxis().isAutomaticMinValue(false);

    chart.getAxes().getVerticalAxis().setMaxValue(15f);
    chart.getAxes().getVerticalAxis().setMinValue(-2f);
    chart.getAxes().getVerticalAxis().setMinorUnit(0.5f);
    chart.getAxes().getVerticalAxis().setMajorUnit(2.0f);

    //Setting Value Axis Text Properties
    IChartPortionFormat txtVal = chart.getAxes().getVerticalAxis().getTextFormat().getPortionFormat();
    txtVal.setFontBold(NullableBool.True);
    txtVal.setFontHeight(16);
    txtVal.setFontItalic(NullableBool.True);
    txtVal.getFillFormat().setFillType(FillType.Solid);
    txtVal.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.DarkGreen));
    txtVal.setLatinFont(new FontData("Times New Roman"));

    //Setting value axis title
    chart.getAxes().getVerticalAxis().hasTitle(true);
    chart.getAxes().getVerticalAxis().getTitle().addTextFrameForOverriding("");
    IPortion valtitle = chart.getAxes().getVerticalAxis().getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0);
    valtitle.setText("Primary Axis");
    valtitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    valtitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
    valtitle.getPortionFormat().setFontHeight(20);
    valtitle.getPortionFormat().setFontBold(NullableBool.True);
    valtitle.getPortionFormat().setFontItalic(NullableBool.True);

    //Setting Major grid lines format for Category axis
    chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GREEN);
    chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().setWidth(5);

    //Setting Minor grid lines format for Category axis
    chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.YELLOW);
    chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().setWidth(3);

    //Setting Category Axis Text Properties
    IChartPortionFormat txtCat = chart.getAxes().getHorizontalAxis().getTextFormat().getPortionFormat();
    txtCat.setFontBold(NullableBool.True);
    txtCat.setFontHeight(16);
    txtCat.setFontItalic(NullableBool.True);
    txtCat.getFillFormat().setFillType(FillType.Solid) ;
    txtCat.getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    txtCat.setLatinFont(new FontData("Arial"));

    //Setting Category Titile
    chart.getAxes().getHorizontalAxis().hasTitle(true);
    chart.getAxes().getHorizontalAxis().getTitle().addTextFrameForOverriding("");

    IPortion catTitle = chart.getAxes().getHorizontalAxis().getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0);
    catTitle.setText("Sample Category");
    catTitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    catTitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
    catTitle.getPortionFormat().setFontHeight(20);
    catTitle.getPortionFormat().setFontBold(NullableBool.True);
    catTitle.getPortionFormat().setFontItalic(NullableBool.True);

    //Setting category axis lable position
    chart.getAxes().getHorizontalAxis().setTickLabelPosition(TickLabelPositionType.Low);

    //Setting category axis lable rotation angle
    chart.getAxes().getHorizontalAxis().setTickLabelRotationAngle(45);

    //Setting Legends Text Properties
    IChartPortionFormat txtleg = chart.getLegend().getTextFormat().getPortionFormat();
    txtleg.setFontBold(NullableBool.True);
    txtleg.setFontHeight(16);
    txtleg.setFontItalic(NullableBool.True);
    txtleg.getFillFormat().setFillType(FillType.Solid);
    txtleg.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.DarkRed));

    //Set show chart legends without overlapping chart

    chart.getLegend().setOverlay(true);
    //chart.ChartData.Series[0].PlotOnSecondAxis=true;

    chart.getChartData().getSeries().get_Item(0).setPlotOnSecondAxis(true);
    //Setting secondary value axis
    chart.getAxes().getSecondaryVerticalAxis().isVisible(true);
     chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().setStyle(LineStyle.ThickBetweenThin);
     chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().setWidth(20);

    //Setting secondary value axis Number format
    chart.getAxes().getSecondaryVerticalAxis().isNumberFormatLinkedToSource(false);
    chart.getAxes().getSecondaryVerticalAxis().setDisplayUnit(DisplayUnitType.Hundreds);
    chart.getAxes().getSecondaryVerticalAxis().setNumberFormat ("0.0%");

    //Setting chart maximum, minimum values
    chart.getAxes().getSecondaryVerticalAxis().isAutomaticMajorUnit(false);
    chart.getAxes().getSecondaryVerticalAxis().isAutomaticMaxValue(false);
    chart.getAxes().getSecondaryVerticalAxis().isAutomaticMinorUnit(false);
    chart.getAxes().getSecondaryVerticalAxis().isAutomaticMinValue(false);

    chart.getAxes().getSecondaryVerticalAxis().setMaxValue(20f);
    chart.getAxes().getSecondaryVerticalAxis().setMinValue(-5f);
    chart.getAxes().getSecondaryVerticalAxis().setMinorUnit(0.5f);
    chart.getAxes().getSecondaryVerticalAxis().setMajorUnit(2.0f);


    //Setting chart back wall color
    chart.getBackWall().setThickness(1);
    chart.getBackWall().getFormat().getFill().setFillType(FillType.Solid);
    chart.getBackWall().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);

    chart.getFloor().getFormat().getFill().setFillType(FillType.Solid);
    chart.getFloor().getFormat().getFill().getSolidFillColor().setColor(Color.GREEN);
    //Setting Plot area color
    chart.getPlotArea().getFormat().getFill().setFillType(FillType.Solid);
    chart.getPlotArea().getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.LightCyan));

    //Save Presentation
    pres.save("data/AsposeFormattedChart.pptx", SaveFormat.Pptx);
    System.out.println("Done");
  }
View Full Code Here

    //Access first slide
    ISlide sld = pres.getSlides().get_Item(0);

    // Add chart with default data
    IChart chart = (IChart)sld.getShapes().get_Item(0);

    //Setting the index of chart data sheet
    int defaultWorksheetIndex = 0;

    //Getting the chart data worksheet
    IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

    //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.getChartData().getSeries().get_Item(0);

    //Now updating series data
    fact.getCell(defaultWorksheetIndex, 0, 1, "New_Series1");//modifying series name
    series.getDataPoints().get_Item(0).getValue().setData (90);
    series.getDataPoints().get_Item(1).getValue().setData ( 123);
    series.getDataPoints().get_Item(2).getValue().setData ( 44);

    //Take Second chart series
    series = chart.getChartData().getSeries().get_Item(1);

    //Now updating series data
    fact.getCell(defaultWorksheetIndex, 0, 2, "New_Series2");//modifying series name
    series.getDataPoints().get_Item(0).getValue().setData (23);
    series.getDataPoints().get_Item(1).getValue().setData ( 67);
    series.getDataPoints().get_Item(2).getValue().setData ( 99);


    //Now, Adding a new series
    chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.getType());

    //Take 3rd chart series
    series = chart.getChartData().getSeries().get_Item(2);

    //Now populating series data
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 3, 20));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 50));
    series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 30));

    chart.setType(ChartType.ClusteredCylinder);

    // Save presentation with chart
    pres.save("data/AsposeChartModified.pptx", SaveFormat.Pptx)
    System.out.println("Done");
View Full Code Here

TOP

Related Classes of com.aspose.slides.IChart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.