问题描述
用jfreechart做的一个.java文件,在MyEclipse中已经调试通过了(RunAs-->JavaApplication),在弹出的窗口图已经显示出来了。但是我不知道如何把它转到web页面上,请教各位高手:packageTest;importjava.awt.*;importjava.text.NumberFormat;importjavax.servlet.http.HttpSession;importjavax.servlet.jsp.JspWriter;importjavax.swing.JPanel;importorg.jfree.chart.*;importorg.jfree.chart.annotations.CategoryTextAnnotation;importorg.jfree.chart.axis.CategoryAnchor;importorg.jfree.chart.axis.NumberAxis;importorg.jfree.chart.labels.*;importorg.jfree.chart.plot.*;importorg.jfree.chart.renderer.category.BarRenderer;importorg.jfree.chart.title.TextTitle;importorg.jfree.data.category.CategoryDataset;importorg.jfree.data.category.DefaultCategoryDataset;importorg.jfree.ui.*;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.Font;importjava.awt.GradientPaint;importjava.awt.Image;importjava.io.IOException;importjavax.imageio.ImageIO;importorg.jfree.chart.ChartFactory;importorg.jfree.chart.ChartPanel;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.axis.AxisLocation;importorg.jfree.chart.axis.CategoryAxis;importorg.jfree.chart.axis.CategoryLabelPositions;importorg.jfree.chart.axis.NumberAxis;importorg.jfree.chart.axis.NumberTickUnit;importorg.jfree.chart.axis.ValueAxis;importorg.jfree.chart.block.BlockContainer;importorg.jfree.chart.block.BorderArrangement;importorg.jfree.chart.block.LabelBlock;importorg.jfree.chart.labels.StandardCategoryItemLabelGenerator;importorg.jfree.chart.plot.CategoryPlot;importorg.jfree.chart.plot.IntervalMarker;importorg.jfree.chart.plot.PlotOrientation;importorg.jfree.chart.renderer.category.BarRenderer;importorg.jfree.chart.renderer.category.LineAndShapeRenderer;importorg.jfree.chart.title.LegendTitle;importorg.jfree.chart.title.TextTitle;importorg.jfree.chart.urls.StandardCategoryURLGenerator;importorg.jfree.data.category.CategoryDataset;importorg.jfree.data.category.DefaultCategoryDataset;importorg.jfree.ui.ApplicationFrame;importorg.jfree.ui.HorizontalAlignment;importorg.jfree.ui.Layer;importorg.jfree.ui.RectangleAnchor;importorg.jfree.ui.RectangleEdge;importorg.jfree.ui.RectangleInsets;importorg.jfree.ui.RefineryUtilities;importorg.jfree.ui.TextAnchor;importorg.jfree.ui.VerticalAlignment;publicclassBarChartDemo4extendsApplicationFrame{privatestaticfinallongserialVersionUID=1L;staticclassCustomBarRendererextendsBarRenderer{publicPaintgetItemPaint(inti,intj){CategoryDatasetcategorydataset=getPlot().getDataset();doubled=categorydataset.getValue(i,j).doubleValue();if(d>=0.69999999999999996D)returnColor.green;elsereturnColor.red;}publicCustomBarRenderer(){}}publicBarChartDemo4(Strings){super(s);CategoryDatasetcategorydataset=createDataset();CategoryDatasetcategorydataset1=createDataset1();JFreeChartjfreechart=createChart(s,categorydataset,categorydataset1);ChartPanelchartpanel=newChartPanel(jfreechart);chartpanel.setPreferredSize(newDimension(500,270));setContentPane(chartpanel);}privatestaticCategoryDatasetcreateDataset(){DefaultCategoryDatasetdefaultcategorydataset=newDefaultCategoryDataset();defaultcategorydataset.addValue(0.77,"Series1","汉字");defaultcategorydataset.addValue(0.93,"Series1","Mary");defaultcategorydataset.addValue(0.58,"Series1","John");defaultcategorydataset.addValue(0.75,"Series1","Ellen");defaultcategorydataset.addValue(0.63,"Series1","Jack");defaultcategorydataset.addValue(0.94,"Series1","David");defaultcategorydataset.addValue(0.70,"Series1","Mark");defaultcategorydataset.addValue(0.50,"Series1","Andy");returndefaultcategorydataset;}privatestaticCategoryDatasetcreateDataset1(){DefaultCategoryDatasetdefaultcategorydataset=newDefaultCategoryDataset();defaultcategorydataset.addValue(87,"Series11","汉字");defaultcategorydataset.addValue(89,"Series11","Mary");defaultcategorydataset.addValue(75,"Series11","John");defaultcategorydataset.addValue(57,"Series11","Ellen");defaultcategorydataset.addValue(76,"Series11","Jack");defaultcategorydataset.addValue(59,"Series11","David");defaultcategorydataset.addValue(47,"Series11","Mark");defaultcategorydataset.addValue(10,"Series11","Andy");returndefaultcategorydataset;}
解决方案
解决方案二:
privatestaticJFreeChartcreateChart(Strings,CategoryDatasetcategorydataset,CategoryDatasetcategorydataset1){JFreeChartjfreechart=ChartFactory.createBarChart("StudentGrades","","进度",categorydataset,PlotOrientation.VERTICAL,false,true,false);jfreechart.setTitle(newTextTitle("Student",newFont("宋体",Font.BOLD,25)));CategoryPlotcategoryplot=(CategoryPlot)jfreechart.getPlot();CustomBarRenderercustombarrenderer=newCustomBarRenderer();custombarrenderer.setBaseItemLabelGenerator(newStandardCategoryItemLabelGenerator());custombarrenderer.setBaseItemLabelsVisible(true);custombarrenderer.setItemLabelAnchorOffset(10D);custombarrenderer.setBasePositiveItemLabelPosition(newItemLabelPosition(ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT));categoryplot.setRenderer(custombarrenderer);ValueMarkervaluemarker=newValueMarker(0.69999999999999996D,newColor(200,200,255),newBasicStroke(1.0F),newColor(200,200,255),newBasicStroke(1.0F),1.0F);valuemarker.setPaint(Color.blue);valuemarker.setLabel("完成");valuemarker.setLabelFont(newFont("SansSerif",0,18));valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);categoryplot.addRangeMarker(valuemarker,Layer.BACKGROUND);custombarrenderer.setBaseItemLabelsVisible(true);custombarrenderer.setMaximumBarWidth(0.05000000000000000);CategoryTextAnnotationcategorytextannotation=newCategoryTextAnnotation("最小","Robert",0.70999999999999996D);categorytextannotation.setCategoryAnchor(CategoryAnchor.START);categorytextannotation.setFont(newFont("宋体",0,12));categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_CENTER);categoryplot.addAnnotation(categorytextannotation);NumberAxisnumberaxis=(NumberAxis)categoryplot.getRangeAxis();numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());numberaxis.setUpperMargin(0.10000000000000001D);ChartUtilities.applyCurrentTheme(jfreechart);CategoryPlotplot=jfreechart.getCategoryPlot();//设置图片的透明度plot.setForegroundAlpha(1f);//plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);//设置第二y轴坐标名NumberAxisnumberAxis=newNumberAxis("销量");//将第二纵坐标间距设置为5numberAxis.setTickUnit(newNumberTickUnit(5));//坐标轴标尺值字体numberAxis.setLabelFont(newFont("Serif",Font.CENTER_BASELINE,30));//装载第二y轴坐标plot.setRangeAxis(1,numberAxis);//设置第二y轴坐标位置plot.setRangeAxisLocation(1,AxisLocation.BOTTOM_OR_RIGHT);//装载第二组数据plot.setDataset(1,categorydataset1);//是第二组数据生成线图plot.setRenderer(1,newLineAndShapeRenderer());//第二个数据映射到第一个数据域x轴plot.mapDatasetToDomainAxis(1,0);//第二个数据映射到第二个数据域y轴plot.mapDatasetToRangeAxis(1,1);//plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);//x坐标轴实例化CategoryAxisxaxis=plot.getDomainAxis();//坐标轴标尺值字体xaxis.setTickLabelFont(newFont("黑体",Font.CENTER_BASELINE,20));xaxis.setLabelFont(newFont("Serif",Font.CENTER_BASELINE,20));ValueAxisyaxis=plot.getRangeAxis();//坐标轴标尺值字体yaxis.setTickLabelFont(newFont("Serif",Font.CENTER_BASELINE,20));yaxis.setLabelFont(newFont("Serif",Font.CENTER_BASELINE,20));returnjfreechart;}publicstaticvoidmain(Stringargs[]){BarChartDemo4barchartdemo4=newBarChartDemo4("JFreeChart:BarChartDemo4.java");barchartdemo4.pack();RefineryUtilities.centerFrameOnScreen(barchartdemo4);barchartdemo4.setVisible(true);}}
解决方案三:
配置一个Servlet就行了
解决方案四:
我是一个菜鸟,能给详细说说吗?
解决方案五:
可以直接把生成的图片放到某个目录下啊,页面上直接就可以用啊