I'm creating a piechart using a piedataset, the data points have a big difference in values. The values being used are {9.0d, 10.0d, 886.0d and 2.0d} This is rendered fine in a chart panel, however when I generate the svg, there is only two distinct colors for the items and they are the wrong colors.
Following is the relevant section of code:
ublic static void main(String... args) throws Exception {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("firewalls", 9.0d);
dataset.setValue("routers", 10.0d);
dataset.setValue("servers", 886.0d);
dataset.setValue("switches", 2.0d);
JFreeChart chart = getChart("Devices", dataset, true);
Chart.renderChart(chart);
Document d = GenericDOMImplementation.getDOMImplementation().createDocument(null, "tmp", null);
SVGGraphics2D graphics = new SVGGraphics2D(d);
graphics.setSVGCanvasSize(new Dimension(600, 400));
chart.draw(graphics, new Rectangle2D.Float(0, 0, 600, 400));
graphics.stream("c:/Documents and Settings/Alan Caudill/Desktop/foo.svg");
}
private static JFreeChart getChart(String chartName, PieDataset dataset, boolean includeLegend) {
JFreeChart chart = ChartFactory.createPieChart(chartName, dataset, includeLegend, false,false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelLinksVisible(true);
plot.setCircular(true);
plot.setIgnoreNullValues(true);
plot.setShadowXOffset(0);
plot.setShadowYOffset(0);
plot.setIgnoreZeroValues(true);
plot.setMinimumArcAngleToDraw(0);
plot.setStartAngle(0);
//plot.setLabelGenerator(new CustomLabelGenerator());//for custom labels
LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
legend.setVerticalAlignment(VerticalAlignment.TOP);
return chart;
}
public static void renderChart(JFreeChart chart) {
ChartPanel panel = new ChartPanel(chart);
JFrame frame = new JFrame();
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
I'm at a loss here. Any help is much appreciated.
problem rendering piechart as svg
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Which version of Batik are you using? I tried your code with Batik 1.7beta1 and didn't see any problem.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

