I created a line chart and when I add the title to my chart it overlaps my data. How do I add the title above my chart? Also how can I adjust the font/style of the title text? I want to make the text a little smaller.
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
Chart chart = drawing.createChart(anchor);
chart.setTitleText("This is my title");
// Use a category axis for the bottom axis.
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
ChartDataSource<Integer> test = DataSources.fromArray([2011,2012,2013,2014,2015,2016,2017] as Integer[]);
ChartDataSource<Integer> test2 = DataSources.fromArray([4805, 7351, 5333, 7183, 6230, 4050, 6963] as Integer[]);
LineChartData data = chart.getChartDataFactory().createLineChartData();
data.addSeries(test, test2);
chart.plot(data, bottomAxis, leftAxis);
So from this example what I looking for is extra padding/margin above the 8000 where my title would go.
So you don't want the title overlaying the plot area?
The problem is that apache poi was tested using Excel 2007. But after this version multiple default settings have been changed in later versions.
The setting of overlays for example had defaulted to false (do not overlay) in Excel 2007 if it was not explicit set. This was a good choice in my opinion. In later versions the default is true (do overlay) if it is not explicit set. That's nonsense in my opinion. But who cares my opinion.
So if we not want the title overlaying the plot area, we have to set this explicitly.
Styling the title font is possible only using the low level underlying objects. Using this we need add run properties to the title's first paragraph and first text run. Then we can set bold, italic and font size (unit 1/100 pt). And then we add type face for latin and complex script characters.
Example code using Java. (The code in the question seems to be Groovy, but it is not tagged as such and there is no answer to my question about this discrepancy.)
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.charts.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
public class LineChartProblem {
public static void main(String[] args) throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
Sheet sheet = wb.createSheet("linechart");
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
Chart chart = drawing.createChart(anchor);
((XSSFChart)chart).setTitleText("This is my title");
//set "the title overlays the plot area" to false explicitly
((XSSFChart)chart).getCTChart().getTitle().addNewOverlay().setVal(false);
//set font style for title - low level
//add run properties to title's first paragraph and first text run. Set bold.
((XSSFChart)chart).getCTChart().getTitle().getTx().getRich().getPArray(0).getRArray(0).addNewRPr().setB(true);
//set italic
((XSSFChart)chart).getCTChart().getTitle().getTx().getRich().getPArray(0).getRArray(0).getRPr().setI(true);
//set font size 20pt
((XSSFChart)chart).getCTChart().getTitle().getTx().getRich().getPArray(0).getRArray(0).getRPr().setSz(2000);
//add type face for latin and complex script characters
((XSSFChart)chart).getCTChart().getTitle().getTx().getRich().getPArray(0).getRArray(0).getRPr().addNewLatin().setTypeface("Times New Roman");
((XSSFChart)chart).getCTChart().getTitle().getTx().getRich().getPArray(0).getRArray(0).getRPr().addNewCs().setTypeface("Times New Roman");
// Use a category axis for the bottom axis.
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
ChartDataSource<Integer> test = DataSources.fromArray(new Integer[]{2011,2012,2013,2014,2015,2016,2017});
ChartDataSource<Integer> test2 = DataSources.fromArray(new Integer[]{4805, 7351, 5333, 7183, 6230, 4050, 6963});
LineChartData data = chart.getChartDataFactory().createLineChartData();
data.addSeries(test, test2);
chart.plot(data, bottomAxis, leftAxis);
// Write the output to a file
try (FileOutputStream fileOut = new FileOutputStream("ooxml-line-chart.xlsx")) {
wb.write(fileOut);
}
}
}
}
Related
I did some searching around the internet (and the code inspection), but it seems I cannot find what im looking for...
What I do:
I´m creating a pie chart in an excel which works fine, EXCEPT that the percent values are shown with top many decimal places:
I played a bit around in the generated Excel and it would help if I could access the "Category" - Numbers property programmatically:
In my code I already tried to set the number format, which doesn´t change anything for me:
public void createPieChartInSheet(Workbook wb, XSSFDrawing drawing, String chartTitle, XSSFClientAnchor anchor, LinkedList<Triple<String, XDDFDataSource<String>, XDDFNumericalDataSource<Double>>> chartSeries, LinkedList<byte[]> colorScheme) {
XSSFChart chart = drawing.createChart(anchor);
chart.setTitleText(chartTitle);
chart.setTitleOverlay(false);
XDDFDataSource<String> cat = chartSeries.get(0).getMiddle();
XDDFNumericalDataSource<Double> val = chartSeries.get(0).getRight();
XDDFChartData data = chart.createData(ChartTypes.PIE, null, null);
Series series = data.addSeries(cat, val);
series.setTitle(chartSeries.get(0).getLeft(), null);
// Add data labels
if (!chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).isSetDLbls()) {
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
}
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowVal().setVal(true);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowSerName().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowCatName().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowPercent().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewNumFmt().setFormatCode("0,00");
setPieChartColors(colorScheme, chart, series);
chart.plot(data);
}
Am I even searching for the right thing? Any help appreciated - thank you!
An Excel chart get it's data label number format from the number format of the cells where the values are stored. That's called "source linked" and is the default. So simply do formatting those cells using the number format you want.
But if you want to have the data labels a special other number format, you need add a NumFmt element to the DLbls element. You have done tis alrady. But this NumFmt must not be source linked then. And it must have it's own FormatCode, which is always en_US in the XML. The localizing is done by the Excel GUI and not in the source XML. So it would must be 0.00 in your case since dot is decimal separator while comma is thousands separator in en_US. But if you want have it the default decimal number format having two decimal digits, it would must be #,##0.00.
Change your code as follows:
...
// Add data labels
if (!chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).isSetDLbls()) {
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
}
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowVal().setVal(true);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowSerName().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowCatName().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowPercent().setVal(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(false);
//chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewNumFmt().setFormatCode("0,00");
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().addNewNumFmt();
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().getNumFmt().setSourceLinked(false);
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls().getNumFmt().setFormatCode("#,##0.00");
...
This works for me and leads to have data labels the number format #.##0,00 in my German Excel, which is the default decimal number format having two decimal digits.
It is always difficult to figure out problem related to Excel, as documentation is not clear and there are so many XML tag with meaningless name.
One way I find useful is to compare the actual xml of working and not working excel file.
So I created a not working excel using program, and then edit using MS Excel to apply formatting to create a working excel.
Then by comparing xl\charts\chart1.xml after unzip the excel,
The problem is found and due to the following line
From program
<c:numFmt formatCode="0.00"/>
After edit with MS Excel
<c:numFmt formatCode="0.00" sourceLinked="0"/>
"0" is false and the default value is "1"(true).
From the document of sourceLinked, I guess the formatting will follow the source(cell original format) when set to true, so we need to set to false to make our formatting effective. We can do so by calling CTNumFmt#setSourceLinked(boolean) with false.
Following program demonstrate how to generate Pie chart with custom number format.(Base on Axel Richter answer), running on POI 4.1.1.
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xddf.usermodel.chart.ChartTypes;
import org.apache.poi.xddf.usermodel.chart.LegendPosition;
import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
import org.apache.poi.xssf.usermodel.XSSFChart;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTDLbls;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
public class CustomDecimalPlace {
public static void main(String[] args) throws FileNotFoundException, IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet("piechart");
final int NUM_OF_ROWS = 2;
final int NUM_OF_COLUMNS = 10;
// Create a row and put some cells in it. Rows are 0 based.
Row row;
Cell cell;
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
row = sheet.createRow((short) rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
cell = row.createCell((short) colIndex);
if (rowIndex == 0) {
cell.setCellValue("Cat " + (colIndex + 1));
} else {
cell.setCellValue(((double) 101) / ((double) (colIndex + 1)));
}
}
}
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 4, 10, 25);
XSSFChart chart = drawing.createChart(anchor);
chart.setTitleText("Pie Chart");
chart.setTitleOverlay(false);
XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
XDDFDataSource<String> cat = XDDFDataSourcesFactory.fromStringCellRange(sheet,
new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
XDDFNumericalDataSource<Double> val = XDDFDataSourcesFactory.fromNumericCellRange(sheet,
new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
XDDFChartData data = chart.createData(ChartTypes.PIE, null, null);
data.setVaryColors(true);
data.addSeries(cat, val);
chart.plot(data);
if (!chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).isSetDLbls()) {
chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
}
CTDLbls dLbls = chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).getDLbls();
dLbls.addNewShowVal().setVal(true);
dLbls.addNewShowSerName().setVal(false);
dLbls.addNewShowCatName().setVal(false);
dLbls.addNewShowPercent().setVal(false);
dLbls.addNewShowLegendKey().setVal(false);
CTNumFmt addNewNumFmt = dLbls.addNewNumFmt();
addNewNumFmt.setFormatCode("0.00");
// Set false to not follow source format
addNewNumFmt.setSourceLinked(false);
// Write the output to a file
try (FileOutputStream fileOut = new FileOutputStream("ooxml-pie-chart.xlsx")) {
wb.write(fileOut);
}
}
}
}
In the excel, here's what I expect, as shown below
enter image description here
In the excel, there is a data labels on the chart, the values displayed default to horizontal, I can set text direction to rotate all text 270 in the text options of format data labels. but, I don't know how to implement this in code with apache poi? Could anyone help?
Here is the code:
XSSFDrawing drawing = (XSSFDrawing)sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 4, 27, 5);
XSSFChart chart = drawing.createChart(anchor);
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
bottomAxis.setTitle("Week");
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setTitle("Face Amount ($MM)");
leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
leftAxis.setMaximum(10000);
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange((XSSFSheet) sheet,
new CellRangeAddress(299, 299, 0, NUM_OF_COLUMNS - 1));
XDDFNumericalDataSource<Double> ys = XDDFDataSourcesFactory.fromNumericCellRange((XSSFSheet) sheet,
new CellRangeAddress(300, 300, 0, NUM_OF_COLUMNS - 1));
XDDFChartData data = chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
XDDFChartData.Series series1 = data.addSeries(xs, ys);
series1.setTitle("2x", null);
chart.plot(data);
XDDFBarChartData bar = (XDDFBarChartData) data;
bar.setBarDirection(BarDirection.COL);
bar.setGapWidth(3);
bar.setBarGrouping(BarGrouping.STACKED);
//set data labels
XSSFChart xssfChart = (XSSFChart) chart;
CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
CTBoolean ctBool = CTBoolean.Factory.newInstance();
ctBool.setVal(true);
plotArea.getBarChartArray(0).getSerArray(0).addNewDLbls().setShowVal(ctBool);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().addNewShowLeaderLines();
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowLeaderLines(ctBool);
ctBool.setVal(false);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowSerName(ctBool);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowPercent(ctBool);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowLegendKey(ctBool);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowCatName(ctBool);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowLeaderLines(ctBool);
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().setShowBubbleSize(ctBool);
As your code shows, you are setting the data labels using the underlying low level beans of apache poi.
But how can one working with those? There is no documentation about org.openxmlformats.schemas.drawingml.x2006.chart.* classes public available. So we need downloading the sources of ooxml-schemas from maven for example. Then we can use javadoc to create a API documentation. Now we can look how to create and use the classes.
But also we need the meanings of the XML elements and attributes, the classes are creating. For this one could study the Office Open XML specifications. But my preferred method is to create a simple *.xlsx file having the needed settings using Excel's GUI. Then unzip that *.xlsx file and have a look at the XML in the *.xml files stored in that ZIP archive. For the first chart this is /xl/charts/chart1.xml.
Doing this we will find:
<c:dLbls>
<c:txPr>
<a:bodyPr rot="-5400000"/>
<a:p><a:pPr><a:defRPr/></a:pPr></a:p>
</c:txPr>
...
</c:dLbls>
for data labels when text rotation is set.
That is a txPr (text properties) element in dLbls having a bodyPr (body properties) element having a rot attribute set. Value of the rot attribute is rotation angle * 60000. The -5400000 for example is -90.00 * 60000. Also there is a p (paragraph) element having a pPr (paragraph properties) element having a defRPr (default run properties) to set that the data label text runs have default properties.
Putting all together the code used in apache poi for this would be:
...
// text properties having rotation set
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().addNewTxPr()
.addNewBodyPr().setRot((int)(-90.00 * 60000));
// paragraph properties having default run properties set
plotArea.getBarChartArray(0).getSerArray(0).getDLbls().getTxPr()
.addNewP().addNewPPr().addNewDefRPr();
...
where plotArea is CTPlotArea as in your code. And the first series must have dLbls set using addNewDLbls as you done in your code.
I'm dealing with POI to create charts and I've some issues.
First, even if I change the AxisPosition I always have x-axis at bottom and y-axis at left. Second I would like to have 2 y-axis. Here's a part of my code:
Function to create the chart:
private XSSFChart createChart(Sheet sheet,int[] anchors, String xLabel, String yLabel, String title){
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(anchors[0], anchors[1], anchors[2],
anchors[3], anchors[4], anchors[5], anchors[6], anchors[7] );
XSSFChart chart = (XSSFChart) drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.TOP);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
ValueAxis rightAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.RIGHT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
//Function to set axis title took from how-to-set-axis-labels-in-a-line-chart-using-apache-poi
setValueAxisTitle(chart,0,yLabel);
setValueAxisTitle(chart,0,"Second Axis");
setCatAxisTitle(chart,0,xLabel);
chart.setTitle(title);
chart.getAxis();
return chart;
}
Code to plot chart
XSSFChart chart1=createChart(sheet,anchor1,"Temps","Courbes",title );
LineChartData dataM3s = chart1.getChartDataFactory().createLineChartData();
ChartDataSource<Number> yM3s = DataSources.fromNumericCellRange(sheet,
new CellRangeAddress(3, (numOfRows / numOfColumns) + 2, colToWrite, colToWrite));
LineChartSeries chartSeriesM3s = dataM3s.addSeries(xs, yM3s);
chartSeriesM3s.setTitle(metric.getLibelle());
chart1.plot(dataOther, chart1.getAxis().get(0), chart1.getAxis().get(1));
//By the way, this works as well:
//chart1.plot(dataM3s, new ChartAxis[] { chart1.getAxis().get(0), chart1.getAxis().get(1)});
When I change
chart1.plot(dataOther, chart1.getAxis().get(0), chart1.getAxis().get(1));
by
chart1.plot(dataOther, chart1.getAxis().get(0), chart1.getAxis().get(2));
I can't open my xlsx file (and as soon as try to create a second value axis): i got message like "unreadable content". sometimes excel suceed in reparing and tells me it repared the drawing shape in /xl/drawings/drawing1.xml. I got this error: error062800_01.xml but not familiar with XML.
If anyone has some idea
i am using the following code to set water mark in the excel sheet, i also get the water mark but instead of showing the watermark at the back round it shows the water mark at foreground.
how to resolve this, the code :
//to add water mark
HSSFPatriarch dp = sheet.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor
(0, 0, 1023, 255, (short) 2, 4, (short) 13, 26);
HSSFTextbox txtbox = dp.createTextbox(anchor);
HSSFRichTextString rtxt = new HSSFRichTextString("POC");
HSSFFont draftFont = hwb.createFont();
draftFont.setColor((short) 27);
draftFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
draftFont.setFontHeightInPoints((short) 192);
draftFont.setFontName("Verdana");
rtxt.applyFont(draftFont);
txtbox.setString(rtxt);
txtbox.setLineStyle(HSSFShape.LINESTYLE_NONE);
txtbox.setNoFill(true);
also how to merge the cells to add title at the top of the excel sheet using poi in java?
Please help me to find and resolve the isssue.
Is there a way of creating and inserting a bar chart in a Ms Word document using Aspose Words for Java? I can't find a way to do this. Thanks.
Aspose.Words for Java currently doesn't allow you to create the bar chart in Word documents. However, if you just want to add a static bar chart, you may try Aspose.Cells for Java to create bar chart and render it to image. After that, you can add this bar chart image in Word document using Aspose.Words for Java. Do you think this might help in your scenario? If it does then you can use the following code snippet to create and render the bar chart to image:
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.getWorksheets().get(0);
//Set the name of worksheet
sheet.setName("Data");
//Get the cells collection in the sheet.
Cells cells = workbook.getWorksheets().get(0).getCells();
//Put some values into a cells of the Data sheet.
cells.get("A1").setValue("Region");
cells.get("A2").setValue("France");
cells.get("A3").setValue("Germany");
cells.get("A4").setValue("England");
cells.get("A5").setValue("Sweden");
cells.get("A6").setValue("Italy");
cells.get("A7").setValue("Spain");
cells.get("A8").setValue("Portugal");
cells.get("B1").setValue("Sale");
cells.get("B2").setValue(70000);
cells.get("B3").setValue(55000);
cells.get("B4").setValue(30000);
cells.get("B5").setValue(40000);
cells.get("B6").setValue(35000);
cells.get("B7").setValue(32000);
cells.get("B8").setValue(10000);
//Create chart
int chartIndex = sheet.getCharts().add(ChartType.COLUMN, 12, 1, 33,
12);
Chart chart = sheet.getCharts().get(chartIndex);
//Set properties of chart title
chart.getTitle().setText("Sales By Region");
chart.getTitle().getTextFont().setBold(true);
chart.getTitle().getTextFont().setSize(12);
//Set properties of nseries
chart.getNSeries().add("Data!B2:B8", true);
chart.getNSeries().setCategoryData("Data!A2:A8");
//Set the fill colors for the series's data points (France -
Portugal(7 points))
ChartPointCollection chartPoints =
chart.getNSeries().get(0).getPoints();
ChartPoint point = chartPoints.get(0);
point.getArea().setForegroundColor(Color.getCyan());
point = chartPoints.get(1);
point.getArea().setForegroundColor(Color.getBlue());
point = chartPoints.get(2);
point.getArea().setForegroundColor(Color.getYellow());
point = chartPoints.get(3);
point.getArea().setForegroundColor(Color.getRed());
point = chartPoints.get(4);
point.getArea().setForegroundColor(Color.getBlack());
point = chartPoints.get(5);
point.getArea().setForegroundColor(Color.getGreen());
point = chartPoints.get(6);
point.getArea().setForegroundColor(Color.getMaroon());
//Set the legend invisible
chart.setShowLegend(false);
//Get the Chart mage
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions();
imgOpts.setImageFormat(ImageFormat.getPng());
//Save the chart image file.
chart.toImage(new FileOutputStream("D:\Files\MyChartImage.png"),
imgOpts);
Disclosure: I work as developer evangelist at Aspose.