problem rendering piechart as svg

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
beena
Posts: 3
Joined: Thu Mar 22, 2007 9:40 pm

problem rendering piechart as svg

Post by beena » Mon Apr 09, 2007 7:18 am

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.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Apr 10, 2007 11:06 am

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked