• <menu id="w2i4a"></menu>
  • logo Spire.XLS 系列教程

    文檔首頁>>Spire.XLS 系列教程>>Spire.XLS教程:在Java中以編程方式在Excel中創(chuàng)建多級類別圖表

    Spire.XLS教程:在Java中以編程方式在Excel中創(chuàng)建多級類別圖表


    Spire.XLS for Java是專業(yè)的Java Excel API,使開發(fā)人員無需使用Microsoft Office或Microsoft Excel即可創(chuàng)建,管理,操作,轉換和打印Excel工作表。

    本文演示了如何使用 Spire.XLS for Java 在 Excel 中創(chuàng)建多級類別圖表。

    免費下載Spire.XLS最新版


    代碼如下:

    import com.spire.xls.*;
    import com.spire.xls.charts.*;
    
    public class CreateMultiLevelChart {
        public static void main(String []args) throws Exception {
            //create a workbook
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.getWorksheets().get(0);
    
            //write data to cells
            sheet.getCellRange("A1").setText( "Main Category");
            sheet.getCellRange("A2").setText("Fruit");
            sheet.getCellRange("A6").setText("Vegies");
            sheet.getCellRange("B1").setText("Sub Category");
            sheet.getCellRange("B2").setText( "Bananas");
            sheet.getCellRange("B3").setText( "Oranges");
            sheet.getCellRange("B4").setText( "Pears");
            sheet.getCellRange("B5").setText("Grapes");
            sheet.getCellRange("B6").setText( "Carrots");
            sheet.getCellRange("B7").setText( "Potatoes");
            sheet.getCellRange("B8").setText( "Celery");
            sheet.getCellRange("B9").setText( "Onions");
            sheet.getCellRange("C1").setText("Value");
            sheet.getCellRange("C2").setValue("52");
            sheet.getCellRange("C3").setValue( "65");
            sheet.getCellRange("C4").setValue( "50");
            sheet.getCellRange("C5").setValue( "45");
            sheet.getCellRange("C6").setValue( "64");
            sheet.getCellRange("C7").setValue( "62");
            sheet.getCellRange("C8").setValue( "89");
            sheet.getCellRange("C9").setValue( "57");
    
            //vertically merge cells from A2 to A5, A6 to A9
            sheet.getCellRange("A2:A5").merge();
            sheet.getCellRange("A6:A9").merge();
            sheet.autoFitColumn(1);
            sheet.autoFitColumn(2);
    
            //add a clustered bar chart to worksheet
            Chart chart = sheet.getCharts().add(ExcelChartType.BarClustered);
            chart.setChartTitle( "Value");
            chart.getPlotArea().getFill().setFillType( ShapeFillType.NoFill);
            chart.getLegend().delete();
            chart.setLeftColumn(5);
            chart.setTopRow(1);
            chart.setRightColumn(14);
    
            //set the data source of series data
            chart.setDataRange(sheet.getCellRange("C2:C9"));
            chart.setSeriesDataFromRange(false);
    
            //set the data source of category labels
            ChartSerie serie = chart.getSeries().get(0);
            serie.setCategoryLabels( sheet.getCellRange("A2:B9"));
    
            //show multi-level category labels
            chart.getPrimaryCategoryAxis().setMultiLevelLable( true);
    
            //save the document
            workbook.saveToFile("output/createMultiLevelChart.xlsx", ExcelVersion.Version2013);
        }
    }

    輸出結果:

    國產Excel開發(fā)組件Spire.XLS教程:在Java中以編程方式在Excel中創(chuàng)建多級類別圖表

    慧都是E-iceblue官方友好合作伙伴,如果您對spire.xls,可以聯(lián)系在線客服了解具體授權價格和使用機制
    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();