With ChartHandle, you can add cells to a chart, change a chart’s title, axis labels, and copy charts between other worksheets and workbooks.
Begin by retrieving a ChartHandle from an existing chart in a worksheet. To retrieve a ChartHandle, use the ChartHandle WorkSheetHandle.getChart(String chartname) method.
try{
ChartHandle performancechart = mysheet.getChart('Performance');
}catch(ChartNotFoundException e){
// oops!
};
With a ChartHandle, you can add cells to the chart using the ChartHandle.changeSeriesRange(String originalrange, String newrange) method.
if(performancechart.changeSeriesRange('Sheet1!C23:E23', 'Sheet1!C23:G23')){
System.out.println('Successfully Added Columns F and G to Series Range');
}
To change the chart title, use the Charthandle.setTitle(String title) method.
performancechart.setChartTitle('Athletic Performance Results');
To change the axis labels, or other text labels in the chart use the ChartHandle.changeTextValue(String originaltext, String newtext) method.
if(ct.changeTextValue('50 Meter Dash Times", "High Jump Distance')){
System.out.println('Successfully Changed Categories Label');
}
To copy a chart into another sheet or workbook, use:
book.copyChartToSheet("New Chart Title", "Sheet3");