jfreechart 数据点显示消息0点显示为上午12点,12点显示为下午12点

来源:互联网 发布:php 判断是否二维数组 编辑:程序博客网 时间:2024/03/29 09:23

jfreechart 当鼠标放在数据点时,提示信息中,0点显示为上午12点,12点显示为下午12点,请用过jfreechart的大侠指点迷津,谢谢了。

 

 

RealTimeWangYa ry = new RealTimeWangYa();
 List list = ry.getList(powersupplyarm.split(",")[0], powersupplyarm
   .split(",")[1], mindate, maxdate);
 final TimeSeries series = new TimeSeries("网压曲线", Second.class);
 Font font = new Font("宋体", Font.BOLD, 12);
 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 // TimeZone zone=TimeZone.getTimeZone("GMT+8"); //获取中国时区
 //TimeZone.setDefault(zone); //设置时区
 for (int i = 0; i < list.size(); i++) {
  List info = (List) list.get(i);
  series.addOrUpdate(
    new Second(df.parse(info.get(5).toString())), Double
      .parseDouble(info.get(7).toString()));
 }
 final TimeSeriesCollection dataset = new TimeSeriesCollection(
   series);
 final String chartTitle = "网压";
 final JFreeChart chart = ChartFactory.createTimeSeriesChart(
   chartTitle, "时间", "网压", dataset, true, true, false);
 TextTitle title1 = new TextTitle("", font);//副标题
 chart.setTitle(title1); //标题
 final XYPlot plot = chart.getXYPlot();
 XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) plot
   .getRenderer();
 xylineandshaperenderer.setSeriesPaint(0, new Color(0, 0, 255));
 {
  //显示曲线点上的数值
  //xylineandshaperenderer.setItemLabelsVisible(true);
  //xylineandshaperenderer.setBaseItemLabelsVisible(true);
  //DecimalFormat f1=new DecimalFormat("##");
  //xylineandshaperenderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{2}",f1,f1)); 
  //xylineandshaperenderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
  //xylineandshaperenderer.setItemLabelFont(new Font("Dialog", 1, 8));
  //plot.setRenderer(xylineandshaperenderer);
 }
 plot.setBackgroundPaint(Color.white);//设置网格背景颜色
 plot.setDomainGridlinePaint(Color.pink);//设置网格竖线颜色
 plot.setRangeGridlinePaint(Color.pink);//设置网格横线颜色
 plot.setAxisOffset(new RectangleInsets(0D, 0D, 0D, 10D));//设置曲线图与xy轴的距离,即曲线与xy轴贴近的距离
 //xylineandshaperenderer.setBaseShapesVisible(true);//设置曲线是否显示数据点
 //plot.getDomainAxis().setLabelGenerator(new CategoryLabelGenerator());

 plot.getDomainAxis().setLabelFont(font);//设置横坐标中文乱码
 plot.getRangeAxis().setLabelFont(font);//y轴注释字体
 //    plot.getRangeAxis().setAutoRangeMinimumSize(18700.0);    //设置Y轴的最小值
 plot.setNoDataMessageFont(font);
 final Marker marker_min = new ValueMarker(18700.0);
 marker_min.setPaint(Color.RED);
 marker_min.setAlpha(1.0f);
 final Marker marker = new ValueMarker(29300.0);
 marker.setPaint(Color.RED);
 marker.setAlpha(1.0f);
 plot.addRangeMarker(marker_min);
 plot.addRangeMarker(marker);
 plot.setBackgroundPaint(null);
 //      plot.setBackgroundImage(JFreeChart.INFO.getLogo());
 chart.getLegend().setItemFont(font);

 StandardEntityCollection sec = new StandardEntityCollection();
 ChartRenderingInfo info = new ChartRenderingInfo(sec);
 PrintWriter w = new PrintWriter(out);//输出MAP信息
 String filename = ServletUtilities.saveChartAsJPEG(chart, 1024,
   670, info, session);

 ChartUtilities.writeImageMap(w, "map0", info, false);
 String graphURL = request.getContextPath()
   + "/train/wangya?filename=" + filename;

 String strimg = ChartUtilities.getImageMap(filename, info);

原创粉丝点击