use of org.apache.poi.hssf.record.chart.LegendRecord in project poi by apache.
the class HSSFChart method createLegendRecord.
private LegendRecord createLegendRecord() {
LegendRecord r = new LegendRecord();
r.setXAxisUpperLeft(3542);
r.setYAxisUpperLeft(1566);
r.setXSize(437);
r.setYSize(213);
r.setType(LegendRecord.TYPE_RIGHT);
r.setSpacing(LegendRecord.SPACING_MEDIUM);
r.setAutoPosition(true);
r.setAutoSeries(true);
r.setAutoXPositioning(true);
r.setAutoYPositioning(true);
r.setVertical(true);
r.setDataTable(false);
return r;
}
use of org.apache.poi.hssf.record.chart.LegendRecord in project poi by apache.
the class HSSFChart method getSheetCharts.
/**
* Returns all the charts for the given sheet.
*
* NOTE: You won't be able to do very much with
* these charts yet, as this is very limited support
*/
public static HSSFChart[] getSheetCharts(HSSFSheet sheet) {
List<HSSFChart> charts = new ArrayList<HSSFChart>();
HSSFChart lastChart = null;
HSSFSeries lastSeries = null;
// Find records of interest
List<RecordBase> records = sheet.getSheet().getRecords();
for (RecordBase r : records) {
if (r instanceof ChartRecord) {
lastSeries = null;
lastChart = new HSSFChart(sheet, (ChartRecord) r);
charts.add(lastChart);
} else if (r instanceof LinkedDataRecord) {
LinkedDataRecord linkedDataRecord = (LinkedDataRecord) r;
if (lastSeries != null) {
lastSeries.insertData(linkedDataRecord);
}
}
if (lastChart == null) {
continue;
}
if (r instanceof LegendRecord) {
lastChart.legendRecord = (LegendRecord) r;
} else if (r instanceof SeriesRecord) {
HSSFSeries series = new HSSFSeries((SeriesRecord) r);
lastChart.series.add(series);
lastSeries = series;
} else if (r instanceof ChartTitleFormatRecord) {
lastChart.chartTitleFormat = (ChartTitleFormatRecord) r;
} else if (r instanceof SeriesTextRecord) {
// Applies to a series, unless we've seen a legend already
SeriesTextRecord str = (SeriesTextRecord) r;
if (lastChart.legendRecord == null && lastChart.series.size() > 0) {
HSSFSeries series = lastChart.series.get(lastChart.series.size() - 1);
series.seriesTitleText = str;
} else {
lastChart.chartTitleText = str;
}
} else if (r instanceof ValueRangeRecord) {
lastChart.valueRanges.add((ValueRangeRecord) r);
} else if (r instanceof Record) {
Record record = (Record) r;
for (HSSFChartType type : HSSFChartType.values()) {
if (type == HSSFChartType.Unknown) {
continue;
}
if (record.getSid() == type.getSid()) {
lastChart.type = type;
break;
}
}
}
}
return charts.toArray(new HSSFChart[charts.size()]);
}
Aggregations