Documents for Excel, Java Edition Documentation
Features / Chart / Chart Types / Bar Chart
In This Topic
    Bar Chart
    In This Topic

    Bar charts compare categorical data through horizontal bars, where length of each bar represents the value of the corresponding category. In bar charts, categories are organized along the vertical axis and data values along the horizontal axis. For example, sales of various product categories can be presented through a bar chart.

    GcExcel supports the following types of bar charts.

    Chart Type Chart Snapshot Use Case
    BarClustered
    BarClustered chart

    BarClustered chart

    BarClustered Chart can be used to display the comparisons of values across different categories.
    BarClustered3D
    BarClustered3D chart

    BarClustered3D chart

    BarClustered3D chart is used to display the chart demonstration in 3D,which is a modification of 2DBarClustered chart. It does not have a third dimension, it only looks volumetric in appearance.
    BarStacked
    BarStacked chart

    BarStacked chart

    BarStacked chart is used to display the relationship of each item/category to the whole in two-dimensional and three-dimensional rectangles.
    BarStacked3D
    BarStacked3D chart

    BarStacked3D chart

    BarStacked3D chart is used to represent the BarStacked chart demonstration in 3D,which looks volumetric in appearance.
    BarStacked100
    BarStacked100 chart

    BarStacked100 chart

    BarStacked100 chart is used to display the comparisons of percentage that each of the values contribute to the total across different categories.

    BarStacked1003D
    BarStacked1003D chart

    BarStacked1003D chart

    BarStacked1003D chart is used to represent the BarStacked100 chart demonstration in 3D, which is a modification of 2D chart in appearance.

    Using Code

    Refer to the following example code to add Bar Stacked Chart:

    Java
    Copy Code
    private static void BarCharts() {
        // Initialize workbook
        Workbook workbook = new Workbook();
        // Fetch default worksheet
        IWorksheet worksheet = workbook.getWorksheets().get(0);
        // Prepare data for chart
        worksheet.getRange("A1:D4")
                .setValue(new Object[][] { 
                    { null, "Q1", "Q2", "Q3" }, 
                    { "Mobile Phones", 1330, 2345, 3493 },
                    { "Laptops", 2032, 3632, 2197 }, 
                    { "Tablets", 6233, 3270, 2030 } });
        worksheet.getRange("A:D").getColumns().autoFit();
        // Add BarStaked Chart
        IShape areaChartShape = worksheet.getShapes().addChart(ChartType.BarStacked, 250, 20, 360, 230);
    
        // Adding series to SeriesCollection
        areaChartShape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D4"), RowCol.Columns, true, true);
    
        // Configure Chart Title
        areaChartShape.getChart().getChartTitle().getTextFrame().getTextRange().getParagraphs()
                .add("Annual Sales Record");
    
        // Saving workbook to Xlsx
        workbook.save("19-BarChart.xlsx", SaveFileFormat.Xlsx);