亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Jfreechart的節點上放上鼠標顯示數據

系統 1936 0

項目需求:移動鼠標,在jfreechart生成的時間曲線圖的節點上,顯示數據。

?

?

具體過程:

資料1 中,列出了用applet實現該功能的例子,

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);
? ? }
}

運行結果如下圖,鼠標放到一數據點,顯示出數值。


?

?

? 需求是在html頁面上顯示,怎樣將applet轉換到html上呢?

?

又找到 資料2 ,關鍵是這句話:“ JFreeChart所產生的原表如何得知滑鼠位置與這個區域的ToolTip、超連結的對應是什麼。事實上,我們還必須替這張圖表在網頁中建立區域對應表”。區域對應表(也稱熱區)怎么生成呢?在她給出了例子中,step5中,提到了生成的方法。


?//Step 1 建立 Dataset 資料結構物件
?HashMap datas = new HashMap();
?datas.put("Java",new Long(721));
?datas.put(".Net",new Long(543));
?datas.put("PHP",new Long(374));
?datas.put("C++",new Long(438));
?datas.put("Others",new Long(424));?
??
?DefaultPieDataset dataSet = new DefaultPieDataset();
?for(Iterator it = datas.keySet().iterator();it.hasNext();){
??String technology = (String)it.next();????
??dataSet.setValue(technology, (Long)datas.get(technology));
?}?
?
?//Step 3 建立 Plot 物件
??????? PiePlot plot = new PiePlot(dataSet);
??????? plot.setInsets(new RectangleInsets(5, 5, 5, 5));
??????? plot.setURLGenerator(new StandardPieURLGenerator("DetailBarChart.jsp","section"));???????
??????? plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
?plot.setExplodePercent(0, 0.2);????????
???????
??????? //Step 4 產生 JFreeChart 物件,並設定圖表底色??????? ?????????
?JFreeChart chart = new JFreeChart("My First Pie Chart",
??????? JFreeChart.DEFAULT_TITLE_FONT,
??????? plot,
??????? true);? ???????????? ?
??????? chart.setBackgroundPaint(Color.LIGHT_GRAY);????????
???????
?//Step 5 輸出圖表,使用 ServletUtilities 將圖表輸出後由 DisplayChart Servlet 讀取
?ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
?String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);???
?PrintWriter writer = new PrintWriter(out);?
?ChartUtilities.writeImageMap(writer, filename, info,false);
?writer.flush();???????? ?
?String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;???????
%>
<html>
?<body>
??<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%= filename %>">
?</body>
</html>

?

step1-step4,生成一個圖表信息chart,只差將其顯示出來。 step5中,

?

?

1、首先調用 ServletUtilities.saveChartAsPNG方法,將chart保存為一張png圖的同時,把圖表的繪制信息保存到info變量中。

2、將圖片路徑和圖片的繪制信息輸出

?ChartUtilities.writeImageMap(writer, filename, info,false);

3、結束

問題:她這里是將生成的圖片保存到某一路徑下,

Jfreechart的節點上放上鼠標顯示數據


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲天天做日日摸天天做 | 中文字幕综合 | 亚洲精品久久99久久 | 国产精品一级毛片不收费 | 欧美日韩中字 | 久久中文字幕不卡一二区 | 国产大尺度视频 | 亚洲精品成人中文网 | 四虎永久免费网站入口2020 | 亚洲国产精品综合久久网络 | 欧美精品福利视频 | 国产香蕉视频 | 国产成人精品一区二三区2022 | 免费一级大毛片a一观看不卡 | 色综合天天综合网站中国 | 欧美一级毛片久久精品 | 国产精品一区二区三区免费视频 | 久在线精品视频 | 国产精品久久久久影院免费 | 亚洲视频在线一区二区 | 天天做天天玩天天爽天天 | 激情综合五月 | 日本aⅴ永久免费网站www | 综合亚洲欧美日韩一区二区 | 欧美日韩国产高清视频 | 久久99精品热在线观看15 | 青草久久久 | 狠狠色伊人亚洲综合第8页 狠狠色综合久久丁香婷婷 狠狠色综合久久婷婷 | 亚洲香蕉一区二区三区在线观看 | 777奇米影视色888成人 | 精品国产一区二区三区不卡 | 国产高清对白国产露脸91 | 青草久| 中文国产成人精品久久一区 | 四虎在线视频观看大全影视 | 日韩欧美一级毛片精品6 | 国产一区曰韩二区欧美三区 | 精品91| 色妇色综合久久夜夜 | 亚洲精品午夜级久久久久 | 四虎最新永久在线精品免费 |