jfreechart 时间序列图当后台提供一个数据点的时候为什么图形上不显示

/**

**QQ:252574345

**MSN:lele_love_lomboz@hotmail.com

*/

 

为了使得时间序列图的时间轴按照一定间隔显示,例如

12:05 12:10 12:15 12:20 12:25 ......这样每隔5分钟显示一个点

 

需要如下设置才能做到:

   SimpleDateFormat frm = new SimpleDateFormat("k:mm");

   DateAxis  dateaxiss=(DateAxis)xyplot.getDomainAxis();

   int count=5;

  //时间轴间距是5分钟,格式为小时:分钟

   dateaxiss.setTickUnit(new DateTickUnit(DateTickUnit.MINUTE, count,frm));  

 

这个时候,当出现一个点的时候,时间轴自动不能设置时间间隔.因为这个后时候没有间距对比,因此,在曲线上,表现为该点不会显示出来

 

 

解决该问题:

 

判断只有曲线点个数>1时候,才设置时间轴间距

 

if(当前曲线点个数>1){

 

   SimpleDateFormat frm = new SimpleDateFormat("k:mm");

   DateAxis  dateaxiss=(DateAxis)xyplot.getDomainAxis();

   int count=5;

  //时间轴间距是5分钟,格式为小时:分钟

   dateaxiss.setTickUnit(new DateTickUnit(DateTickUnit.MINUTE, count,frm));  

 

}

 

 

这样,当出现一个点的时候,会显示出该点

阅读更多
换一批

jfreechart的数据点显示

04-16

小弟我要实现在一个jsp页面上画出两个曲线图,每个图都是以时间为x轴,多纵轴.并且要在鼠标指向各个数据点的时候显示其坐标.rn写了一个方法rn public void drawMoreZheXian(ArrayList TimeSeriesLIst, ArrayList showList,rn ArrayList colorList, String[] groupArr,rn String[] titleArr, String zmStr,rn JspWriter out, int width, int height,rn String[] colorArr, int bgcolor) rn CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(zmStr));rn if (groupArr != null && groupArr.length >= 1) rnrn for (int i = 0; i < groupArr.length; i++) rn //String[] numArr = groupArr[i].split(",");rn// 循环把各组值放到 collection中rn TimeSeriesCollection dataset = new TimeSeriesCollection();rn dataset.addSeries( (TimeSeries) TimeSeriesLIst.get(i));rnrn// 生产工具提示信息的ArrayListrn ArrayList[] tooltips = new ArrayList[showList.size()];rn for (int k = 0; k < showList.size(); k++) rn tooltips[k] = getCurveSeries( (String[]) showList.get(k));rn rnrn ////////////////////////井数rn NumberAxis rangeAxis1 = new NumberAxis(titleArr[i]);rnrn CustomXYToolTipGenerator ttg1 = new CustomXYToolTipGenerator();rn //加入各条曲线的工具提示条rn ttg1.addToolTipSeries(tooltips[i]);rnrnrnrn //生成曲线的透视层rn StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(rn StandardXYItemRenderer.SHAPES_AND_LINES,rn ttg1, null);rn rangeAxis1.setAutoRangeIncludesZero(false);rn rangeAxis1.setAutoRangeStickyZero(false);rn //设置小数位数rn rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());rn XYPlot subplot1 = new XYPlot(dataset, null, rangeAxis1, renderer1);rn subplot1.setBackgroundPaint(new GradientPaint(0, 100,rn new Color(0xccccff), 130, 240, new Color(0xeffcd0), true));rn plot.setDomainGridlinePaint(Color.white);rn plot.setRangeGridlinePaint(Color.white);rn plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));rn plot.add(subplot1, 1);rn plot.setBackgroundPaint(new Color(bgcolor));rn if (colorList != null && colorList.size() > 0) rn renderer1.setSeriesPaint(0, (Color) colorList.get(i));rn rnrn rangeAxis1.setAutoRange(true);rnrn JFreeChart chart = new JFreeChart("",rn JFreeChart.DEFAULT_TITLE_FONT, plot, false);rn chart.setBackgroundPaint(new Color(bgcolor));rnrn plot.setDomainCrosshairVisible(false);rn plot.setRangeCrosshairVisible(false);rnrn DateAxis axis = (DateAxis) plot.getDomainAxis();rn axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1,rn new SimpleDateFormat("MM-dd")));rn XYItemRenderer xyitemrenderer = plot.getRenderer();rn if (xyitemrenderer instanceof XYLineAndShapeRenderer) rn XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)rn xyitemrenderer;rn xylineandshaperenderer.setBaseShapesVisible(true);rn xylineandshaperenderer.setBaseShapesFilled(true);rn rn FileOutputStream fos_jpg = null;rn String[] imgUrl = null;rn ChartRenderingInfo info = null;rn try rn imgUrl = ImgScgz.getImgUrl();rn fos_jpg = new FileOutputStream(imgUrl[0]);rn info = new ChartRenderingInfo();rn ChartUtilities.writeChartAsJPEG(fos_jpg, 100, chart, width, height, info); //图形的大小rnrn rn catch (Exception e) rn e.printStackTrace();rn rn finally rn try rn fos_jpg.close();rn rn catch (Exception e) rn rn try rn out.print("");rn out.print(ChartUtilities.getImageMap("mapName", info));rn rn catch (Exception e) rnrn rnrn然后在jsp中调用两次这个方法,只是传递的参数不一致,但是只能显示前一个图的数据点,后一个似乎还是用的前一个的tooltipsrnrnrn请教高手是怎么回事?

没有更多推荐了,返回首页