日期:2014-05-19 浏览次数:20800 次
String cardId=request.getParameter("cardId"); // Create tooltip and URL generators SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK); DecimalFormat s=new DecimalFormat("#0.0#"); StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator( "({1},{2})", NumberFormat.getInstance(), NumberFormat.getInstance()); // Create the chart object ValueAxis timeAxis = new NumberAxis("纵坐标名称"); NumberAxis valueAxis = new NumberAxis("横坐标名称") valueAxis.setAutoRangeIncludesZero(true); // override default StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, null); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE12,TextAnchor.TOP_LEFT,TextAnchor.CENTER_RIGHT,0D); renderer.setPositiveItemLabelPosition(itemlabelposition); //renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new DecimalFormat("0.00"),new DecimalFormat("0.00"))); //StandardXYItemLabelGenerator s = new StandardXYItemLabelGenerator(); //不可用 //renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator());//设置数据点显示 renderer.setItemLabelsVisible(true); renderer.setShapesFilled(true); XYPlot plot=null; try { plot = new XYPlot(getDataSet(cardId), timeAxis, valueAxis, renderer); } catch (GeneralException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } //取得该类图形的范围数字轴,指纵坐标 NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis(); ///设置纵坐标以标准整形为单位 numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //设置范围坐标的最小值 //numberaxis.setRange(,rangeMaxAxis); //将纵坐标间距设置为50 numberaxis.setTickUnit(new NumberTickUnit(100)); numberaxis.setAutoRangeStickyZero(false); getDomainAndRangeMaxValue(); numberaxis.setRange(minRange,maxRange); NumberAxis dateaxiss=(NumberAxis)plot.getDomainAxis(); dateaxiss.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //DecimalFormat t=new DecimalFormat("#0.0#"); //dateaxiss.setNumberFormatOverride(t); dateaxiss.setTickUnit(new NumberTickUnit(6)); dateaxiss.setRange(0d,maxDomain); JFreeChart chart = new JFreeChart("图形名称", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(java.awt.Color.white); //renderer.setDrawShapes(true); renderer.setSeriesStroke(0, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 10F, 6F }, 0.0F)); renderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 6F }, 0.0F)); renderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 2.0F, 6F }, 0.0F)); plot.setBackgroundPaint(java.awt.Color.white);//设置网格背景色 //plot.setDomainGridlinePaint(Color.green);//设置网格竖线(Domain轴)颜色 plot.setDomainGridlinePaint(java.awt.Color.lightGray); plot.setRangeGridlinePaint(java.awt.Color.lightGray); chart.setBackgroundPaint(new Color(0xCC, 0xCC, 0xFF)); session.setAttribute(ReportConstant.REPORT_DATA,chart); se