Opa galera aproveitando o gancho não estou conseguindo executar o jfreechart com servlet
@WebServlet("/graficoJFreeChartServelt")
public class GraficoJFreeChartServelt extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
response.setContentType("image/jpeg");
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, criarGrafico(), 300, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
private JFreeChart criarGrafico() throws Exception {
Double porcentagem = 1000D;
DefaultValueDataset dataset1 = new DefaultValueDataset(porcentagem);
DefaultValueDataset dataset2 = new DefaultValueDataset(500D);
DialPlot dialplot = new DialPlot();
dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
dialplot.setDataset(0, dataset1);
dialplot.setDataset(1, dataset2);
StandardDialFrame standarddialframe = new StandardDialFrame();
standarddialframe.setBackgroundPaint(Color.lightGray);
standarddialframe.setForegroundPaint(Color.GRAY);
dialplot.setDialFrame(standarddialframe);
GradientPaint gradientpaint = new GradientPaint(new Point(),
new Color(255, 255, 255), new Point(), new Color(170, 170,
220));
DialBackground dialbackground = new DialBackground(gradientpaint);
dialbackground
.setGradientPaintTransformer(new StandardGradientPaintTransformer(
GradientPaintTransformType.VERTICAL));
dialplot.setBackground(dialbackground);
DialTextAnnotation dialtextannotation = new DialTextAnnotation(
"Meta");
dialtextannotation.setFont(new Font("Dialog", 1, 14));
dialtextannotation.setRadius(0.15D);
dialplot.addLayer(dialtextannotation);
Integer meta = 10000;
DialTextAnnotation dialtextaMeta = new DialTextAnnotation("R$ "
+ meta + "mi");
dialtextaMeta.setFont(new Font("Dialog", 0, 14));
dialtextaMeta.setRadius(0.30D);
dialplot.addLayer(dialtextaMeta);
StandardDialScale standarddialscale = new StandardDialScale(0, 150,
270D, -300D, 10D, 1);
standarddialscale.setTickRadius(0.88D);
standarddialscale.setTickLabelOffset(0.18999999999999999D);
standarddialscale.setTickLabelFont(new Font("Dialog", 0, 12));
standarddialscale.setTickLabelFormatter(DecimalFormat
.getNumberInstance());
dialplot.addScale(0, standarddialscale);
dialplot.mapDatasetToScale(1, 1);
StandardDialRange standarddialrange = new StandardDialRange(100D,
150D, Color.GREEN);
standarddialrange.setScaleIndex(0);
standarddialrange.setInnerRadius(0.50999999999999997D);
standarddialrange.setOuterRadius(0.50999999999999997D);
dialplot.addLayer(standarddialrange);
StandardDialRange standarddialrangeb = new StandardDialRange(0D,
100D, Color.RED);
standarddialrangeb.setScaleIndex(0);
standarddialrangeb.setInnerRadius(0.50999999999999997D);
standarddialrangeb.setOuterRadius(0.50999999999999997D);
dialplot.addLayer(standarddialrangeb);
StandardDialScale standarddialscale1 = new StandardDialScale();
standarddialscale1.setTickRadius(0.5D);
standarddialscale1.setTickLabelOffset(0.14999999999999999D);
standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
standarddialscale1.setMajorTickPaint(Color.red);
standarddialscale1.setMinorTickPaint(Color.red);
dialplot.addScale(1, standarddialscale1);
dialplot.mapDatasetToScale(1, 1);
org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(
0);
dialplot.addPointer(pointer);
org.jfree.chart.plot.dial.DialPointer.Pointer pin = new org.jfree.chart.plot.dial.DialPointer.Pointer(
1);
dialplot.addPointer(pin);
JFreeChart jfreechart = new JFreeChart(dialplot);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setPreferredSize(new Dimension(400, 400));
return jfreechart;
}
}
O que pode estar acontencendo? Não da erro nenhum porém não mostra na tela.