I've generated a line chart using Apache POI. I need to change the default colors I got in the chart. Can I use RGB codes to define specific colors to each line?
My code is as follows.
Drawing drawing = sheet4.createDrawingPatriarch();ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 17, 22);Chart chart = drawing.createChart(anchor);ChartLegend legend = chart.getOrCreateLegend();legend.setPosition(LegendPosition.RIGHT);LineChartData data = chart.getChartDataFactory().createLineChartData();ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(1, 380, 0, 0));ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(1, 380, 1, 1));ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(1, 380, 3, 3));ChartDataSource<Number> ys3 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(1, 380, 4, 4));ChartDataSource<Number> ys4 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(1, 380, 8, 8));LineChartSeries series1 = data.addSeries(xs, ys1);series1.setTitle("Value 1");LineChartSeries series2 = data.addSeries(xs, ys2);series2.setTitle("Value 2");LineChartSeries series3 = data.addSeries(xs, ys3);series3.setTitle("Value 3");LineChartSeries series4 = data.addSeries(xs, ys4);series4.setTitle("Value 4");chart.plot(data, bottomAxis, leftAxis);XSSFChart xssfChart = (XSSFChart) chart;CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();plotArea.getLineChartArray()[0].getSmooth();CTBoolean ctBool = CTBoolean.Factory.newInstance();ctBool.setVal(false);plotArea.getLineChartArray()[0].setSmooth(ctBool);for (CTLineSer ser : plotArea.getLineChartArray()[0].getSerArray()) { ser.setSmooth(ctBool);}