package gg;
import java.awt.Color;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.*;
public class TimeSeriesDemo1 extends ApplicationFrame
{
public TimeSeriesDemo1(String s)
{
super(s);
XYDataset xydataset = createDataset();
JFreeChart jfreechart = createChart(xydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart, false);
chartpanel.setPreferredSize(new Dimension(500, 270));
chartpanel.setMouseZoomable(true, false);
setContentPane(chartpanel);
}
private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal
& General Unit Trust Prices", "Date", "Price Per Unit", xydataset,
true, true, true);
jfreechart.setBackgroundPaint(Color.white);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
xyplot.setDomainCrosshairVisible(true);
xyplot.setRangeCrosshairVisible(true);
org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
if(xyitemrenderer instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setBaseShapesFilled(true);
}
DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
return jfreechart;
}
private static XYDataset createDataset()
{
TimeSeries timeseries = new TimeSeries("L&G European Index Trust", org.jfree.data.time.Month.class);
timeseries.add(new Month(2, 2001), 181.80000000000001D);
timeseries.add(new Month(3, 2001), 167.30000000000001D);
timeseries.add(new Month(4, 2001), 153.80000000000001D);
timeseries.add(new Month(5, 2001), 167.59999999999999D);
timeseries.add(new Month(6, 2001), 158.80000000000001D);
timeseries.add(new Month(7, 2001), 148.30000000000001D);
timeseries.add(new Month(8, 2001), 153.90000000000001D);
timeseries.add(new Month(9, 2001), 142.69999999999999D);
timeseries.add(new Month(10, 2001), 123.2D);
timeseries.add(new Month(11, 2001), 131.80000000000001D);
timeseries.add(new Month(12, 2001), 139.59999999999999D);
timeseries.add(new Month(1, 2002), 142.90000000000001D);
timeseries.add(new Month(2, 2002), 138.69999999999999D);
timeseries.add(new Month(3, 2002), 137.30000000000001D);
timeseries.add(new Month(4, 2002), 143.90000000000001D);
timeseries.add(new Month(5, 2002), 139.80000000000001D);
timeseries.add(new Month(6, 2002), 137D);
timeseries.add(new Month(7, 2002), 132.80000000000001D);
TimeSeries timeseries1 = new TimeSeries("L&G UK Index Trust", org.jfree.data.time.Month.class);
timeseries1.add(new Month(2, 2001), 129.59999999999999D);
timeseries1.add(new Month(3, 2001), 123.2D);
timeseries1.add(new Month(4, 2001), 117.2D);
timeseries1.add(new Month(5, 2001), 124.09999999999999D);
timeseries1.add(new Month(6, 2001), 122.59999999999999D);
timeseries1.add(new Month(7, 2001), 119.2D);
timeseries1.add(new Month(8, 2001), 116.5D);
timeseries1.add(new Month(9, 2001), 112.7D);
timeseries1.add(new Month(10, 2001), 101.5D);
timeseries1.add(new Month(11, 2001), 106.09999999999999D);
timeseries1.add(new Month(12, 2001), 110.3D);
timeseries1.add(new Month(1, 2002), 111.7D);
timeseries1.add(new Month(2, 2002), 111D);
timeseries1.add(new Month(3, 2002), 109.59999999999999D);
timeseries1.add(new Month(4, 2002), 113.2D);
timeseries1.add(new Month(5, 2002), 111.59999999999999D);
timeseries1.add(new Month(6, 2002), 108.8D);
timeseries1.add(new Month(7, 2002), 101.59999999999999D);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
timeseriescollection.addSeries(timeseries);
timeseriescollection.addSeries(timeseries1);
return timeseriescollection;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
TimeSeriesDemo1 timeseriesdemo1 = new TimeSeriesDemo1("Time Series Demo 1");
timeseriesdemo1.pack();
RefineryUtilities.centerFrameOnScreen(timeseriesdemo1);
timeseriesdemo1.setVisible(true);
}
}
运行结果如下图,鼠标放到一数据点,显示出数值。
分享到:
相关推荐
4. 鼠标交互:支持鼠标悬停显示提示信息,点击节点进行高亮或其他操作,增强了用户的交互体验。 五、实际应用案例 jTreeChart常用于企业管理软件、数据分析工具和报告生成器中,如展示公司部门结构、项目任务分解...
在实际编程中,为了使图表更具交互性,我们还可能需要引入事件监听器,如鼠标点击事件,以便用户可以查询或修改图表上的特定元素。同时,为了提高用户体验,我们可能还需要考虑图表的动画效果,如平滑过渡和动态更新...
标题“svggrph_examples”表明这是一个关于使用JAVA生成SVG图形的示例集合,可能包含不同类型的图表,如柱状图用于表现分类数据的对比,点图用于显示数据点的关系和分布,以及折线图用于展示数据随时间的变化趋势。...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...