`

分享带热点图提示的 TimeSeries Chart

阅读更多

写这篇文章是为了把自己研究的东西分享给大家,可能大家已经知道了,那我就献丑了。
在做金融相关项目的时候,往往会碰到要画时间序列图,大家都知道jfreechart是我们java玩家选择得比较多的。
但是有个问题,jfreechart的时间序列图好像不能给出带热点提示的图出来,因为jfreechart生成出来的是一张图片,
我参考了网上很多的文章都没有给出一个能真正解决问题的方案,所以自己动手搞出来一个。鼠标放在生成出来的图片上一样可以出现数据提示!代码如下!

带热点提示的TimeSeries图,时间序列图

<%@ page language="java" contentType="text/html; charset=UTF-8"
 pageEncoding="UTF-8"%>
<%@ page import="java.awt.*"%>
<%@ page import="java.io.*"%>
<%@ page import="org.jfree.chart.*"%>
<%@ page import="org.jfree.data.time.*"%>
<%@ page import="org.jfree.chart.plot.*"%>
<%@ page import="org.jfree.ui.*"%>
<%@ page import="org.jfree.data.time.TimeSeriesCollection"%>
<%@ page import="org.jfree.chart.renderer.xy.*"%>
<%@ page import="org.jfree.chart.axis.*"%>
<%@ page import="org.jfree.chart.entity.*"%>
<%@ page import="org.jfree.chart.servlet.*"%>
<%@ page import="org.jfree.chart.urls.*"%>

<HTML>
 <HEAD>
  <TITLE>time series view</TITLE>
 </HEAD>
 <body>
  <%
   TimeSeries xyseries = new TimeSeries("finince income", Month.class);
   xyseries.add(new Month(1, 2007), 1.0D);
   xyseries.add(new Month(2, 2007), 4D);
   xyseries.add(new Month(3, 2007), 3D);
   xyseries.add(new Month(4, 2007), 5D);
   xyseries.add(new Month(5, 2007), 5D);
   xyseries.add(new Month(6, 2007), 7D);
   xyseries.add(new Month(7, 2007), 7D);
   xyseries.add(new Month(8, 2007), 8D);

   TimeSeries xyseries1 = new TimeSeries("avg incross rate",
     Month.class);
   xyseries1.add(new Month(1, 2007), 3.0D);
   xyseries1.add(new Month(2, 2007), 4.9D);
   xyseries1.add(new Month(3, 2007), 3.5D);
   xyseries1.add(new Month(4, 2007), 4.5D);
   xyseries1.add(new Month(5, 2007), 5.5D);
   xyseries1.add(new Month(6, 2007), 7D);
   xyseries1.add(new Month(7, 2007), 7.9D);
   xyseries1.add(new Month(8, 2007), 1.8D);

   TimeSeries xyseries2 = new TimeSeries("incross rate", Month.class);
   xyseries2.add(new Month(1, 2007), 4.0D);
   xyseries2.add(new Month(2, 2007), 6.4D);
   xyseries2.add(new Month(3, 2007), 3.8D);
   xyseries2.add(new Month(4, 2007), 5.9D);
   xyseries2.add(new Month(5, 2007), 8.2D);
   xyseries2.add(new Month(6, 2007), 4.2D);
   xyseries2.add(new Month(7, 2007), 9.7D);
   xyseries2.add(new Month(8, 2007), 5.6D);

   TimeSeriesCollection xyseriescollection = new TimeSeriesCollection();
   xyseriescollection.addSeries(xyseries);
   xyseriescollection.addSeries(xyseries1);
   xyseriescollection.addSeries(xyseries2);

   JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
     "Example", "y", "x", xyseriescollection, true, true, true);
   jfreechart.setBackgroundPaint(Color.white);
   XYPlot xyplot = jfreechart.getXYPlot();

   xyplot.setBackgroundPaint(Color.white);
   xyplot.setRangeGridlinePaint(Color.black);
   xyplot.setDomainGridlinesVisible(false);
   xyplot.setRangeGridlinesVisible(true);
   xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
   xyplot.setDomainCrosshairVisible(true);
   xyplot.setDomainCrosshairLockedOnData(false);
   xyplot.setRangeCrosshairVisible(false);
   xyplot.setBackgroundImageAlpha(1.0f);
   XYItemRenderer xyitemrenderer = xyplot.getRenderer();

   XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) xyplot
     .getRenderer();
   render.setURLGenerator(new StandardXYURLGenerator("view.jsp"));
   render.setBaseShapesVisible(true);
   render.setBaseShapesFilled(true);

   xyitemrenderer.setSeriesPaint(0, Color.black);
   xyitemrenderer.setSeriesPaint(1, Color.red);
   xyitemrenderer.setSeriesStroke(1, new BasicStroke(1.0F, 1, 1, 1.0F,
     new float[] { 5F, 3F }, 0.0F));

   IntervalMarker intervalmarker0 = new IntervalMarker(0D, 2D);
   intervalmarker0.setLabel("qing");
   intervalmarker0.setLabelFont(new Font("SansSerif", 2, 11));
   intervalmarker0.setLabelAnchor(RectangleAnchor.LEFT);
   intervalmarker0.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
   intervalmarker0.setPaint(Color.cyan);
   xyplot.addRangeMarker(intervalmarker0, Layer.BACKGROUND);

   IntervalMarker intervalmarker = new IntervalMarker(2D, 4D);
   intervalmarker.setLabel("huang");
   intervalmarker.setLabelFont(new Font("SansSerif", 2, 11));
   intervalmarker.setLabelAnchor(RectangleAnchor.LEFT);
   intervalmarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
   intervalmarker.setPaint(Color.yellow);
   xyplot.addRangeMarker(intervalmarker, Layer.BACKGROUND);

   IntervalMarker intervalmarker1 = new IntervalMarker(4D, 6D);
   intervalmarker1.setLabel("nan");
   intervalmarker1.setLabelFont(new Font("SansSerif", 2, 11));
   intervalmarker1.setLabelAnchor(RectangleAnchor.LEFT);
   intervalmarker1.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
   intervalmarker1.setPaint(Color.BLUE);
   xyplot.addRangeMarker(intervalmarker1, Layer.BACKGROUND);

   IntervalMarker intervalmarker2 = new IntervalMarker(6D, 8D);
   intervalmarker2.setLabel("nu");
   intervalmarker2.setLabelFont(new Font("SansSerif", 2, 11));
   intervalmarker2.setLabelAnchor(RectangleAnchor.LEFT);
   intervalmarker2.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
   intervalmarker2.setPaint(Color.green);
   xyplot.addRangeMarker(intervalmarker2, Layer.BACKGROUND);

   IntervalMarker intervalmarker3 = new IntervalMarker(8D, 10D);
   intervalmarker3.setLabel("hong");
   intervalmarker3.setLabelFont(new Font("SansSerif", 2, 11));
   intervalmarker3.setLabelAnchor(RectangleAnchor.LEFT);
   intervalmarker3.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
   intervalmarker3.setPaint(Color.RED);
   xyplot.addRangeMarker(intervalmarker3, Layer.BACKGROUND);

   DateAxis domainaxis = (DateAxis) xyplot.getDomainAxis();
   domainaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 2));

   NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
   numberaxis.setTickUnit(new NumberTickUnit(2D));

   String filename = null;
   PrintWriter pw = new PrintWriter(out);
   StandardEntityCollection sec = new StandardEntityCollection();
   ChartRenderingInfo info = new ChartRenderingInfo(sec);

   filename = ServletUtilities.saveChartAsPNG(jfreechart, 800, 600,
     info, session);
   ChartUtilities.writeImageMap(pw, "map0", info, false);// true or false has big diffenrence
   // if choose true,it will js function in html code
   String url = request.getContextPath()
     + "/servlet/DisplayChart?filename=" + filename;
  %>
  <P ALIGN="CENTER">
   <img src="<%=url%>" width=800 height=600 border=1 usemap="#map0">
  </P>
 </body>
</html>

 

欢迎交流 qq 569021135

0
0
分享到:
评论

相关推荐

    R for time series

    标题:“R for time series” 指明本文档是一本使用R语言进行时间序列数据预测分析的经典入门教材。R语言是数据分析领域里非常流行且强大的工具之一,特别是在时间序列分析领域,R语言凭借其丰富的统计包和社区支持...

    TimeSeries时间序列函数_timeseries_matlab_matlab小程序_

    在MATLAB中,时间序列(TimeSeries)是处理和分析有序数据的重要工具,尤其是在金融、工程、气象学等领域。这个MATLAB小程序集可能是为初学者或自学者设计的,旨在帮助理解并应用时间序列分析的基本概念和函数。下面...

    Analyzing Neural Time Series Data图书

    ### Analyzing Neural Time Series Data: Key Insights and Concepts #### Introduction The book "Analyzing Neural Time Series Data: Theory and Practice" by Mike X Cohen is a comprehensive guide designed...

    Hamilton-Time Series Analysis

    Hamilton-Time Series Analysis Hamilton-Time Series Analysis Hamilton-Time Series Analysis

    Matrix factorization for multivariate time series analysis

    It has been used in multivariate time series analysis, leading to the decomposition of the series in a small set of latent factors. However, little is known on the statistical performances of matrix ...

    Deep Learning for Time Series Forecasting - by Jason Brownlee

    Deep Learning for Time Series Forecasting Predict the Future with MLPs, CNNs and LSTMs in Python Jason Brownlee 5 25 step-by-step lessons, 575 pages. 深度学习方法为时间系列预测提供了许多希望,例如...

    hamilton time series analysis

    The book is intended to provide students and researchers with a self-contained survey of time series analysis. It starts from first principles and should be readily accessible to any beginning ...

    Introduction to time series+ Deep Time Series Forecasting with Python

    关于时间序列大数据分析的外文书籍。Introduction to time series.pdf (第三版)+ Deep Time Series Forecasting with Python.pdf 【高清】

    Time Series Analysis and Its Applications.pdf

    Stoffer编著的《Time Series Analysis and Its Applications》是该领域内的重要著作,目前更新至第四版,涵盖了时间序列分析的现代主题,并在前三版的基础上添加了新的主题和数据集。 在第四版中,作者保留了第三...

    Nonlinear time series analysis

    3. **生物医学**:如心电图(ECG)信号处理中,非线性时间序列分析技术可用于识别心脏疾病早期征兆。 4. **电力系统**:监测电网负荷变化,预测电力需求峰值,保障电力供应稳定。 #### 六、发展趋势 随着大数据...

    小波神经网络timeseries 小波神经网络timeseries

    时间序列(Time Series)数据是按时间顺序排列的一系列数值,广泛应用于经济、金融、气象、医学、工程等多个领域。小波神经网络在处理此类数据时,具有局部化、多分辨率分析等优势,能够捕捉到信号的瞬时特征和变化...

    timeseries-analysis, NPM软件包Timeseries分析,噪声去除,统计. ..zip

    timeseries-analysis, NPM软件包Timeseries分析,噪声去除,统计. . Timeseries分析一个可以链接的timeseries分析工具。转换你的数据,过滤它,平滑它,去除噪音,获取统计数据,获取数据的预览图表- - 。这个库是...

    Time series integration classification_python_残差序列_timeseries_An

    在时间序列分析中,"Time series integration classification_python_残差序列_timeseries_An" 主题涉及到的是如何使用Python进行时间序列的整合、分类以及通过残差序列进行异常检测。时间序列数据是按照特定时间...

    Time Series Analysis and Its Applications

    10. 多元时间序列分析(Multivariate Time Series Analysis):当分析两个或两个以上时间序列之间的关系时,会用到多元时间序列分析的方法,这些方法能够帮助我们了解不同时间序列间的动态相互作用。 本书第四版...

    Analyzing Neural Time Series Data Theory and Practice

    "Analyzing Neural Time Series Data: Theory and Practice"这本书及其配套MATLAB代码提供了深入理解这一主题的宝贵资源。MATLAB是一种广泛使用的编程环境,特别适合处理和分析各种类型的数据,包括复杂的时间序列...

    Time Series Analysis and Its Applications With R Examples 4th 2017

    时间序列分析是一门研究按照时间顺序排列的数据点的统计学分支,其目的是从这些数据中提取有用的信息,构建数学模型进行描述、分析、解释和预测。R语言,作为一种开源的统计计算和图形软件,广泛应用于数据分析,...

    Eamonn 教授的综合 Time Series Tutorial

    Eamonn 教授的综合 Time Series Tutorial

    Statistical Signal Processing - Detection, Estimation, and Time Series Analysis

    Statistical Signal Processing - Detection, Estimation, and Time Series Analysis

    Introductory Time Series with R 原版pdf by Cowpertwait & Metcalfe

    time series methods to a variety of data sets. The book assumes the reader has a knowledge typical of a first-year university statistics course and is based around lecture notes from a range of time ...

Global site tag (gtag.js) - Google Analytics