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

Jfreechart的節(jié)點上放上鼠標顯示數(shù)據(jù)

系統(tǒng) 2174 0

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

?

?

具體過程:

資料1 中,列出了用applet實現(xiàn)該功能的例子,

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

運行結(jié)果如下圖,鼠標放到一數(shù)據(jù)點,顯示出數(shù)值。


?

?

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

?

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


?//Step 1 建立 Dataset 資料結(jié)構(gòu)物件
?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 產(chǎn)生 JFreeChart 物件,並設(shè)定圖表底色??????? ?????????
?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、首先調(diào)用 ServletUtilities.saveChartAsPNG方法,將chart保存為一張png圖的同時,把圖表的繪制信息保存到info變量中。

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

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

3、結(jié)束

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

Jfreechart的節(jié)點上放上鼠標顯示數(shù)據(jù)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本aaaa精品免费视频 | 日韩欧美中文字幕一区二区三区 | 色婷婷中文字幕 | 国产免费一区二区三区免费视频 | 日韩久久影院 | 国产精品一区高清在线观看 | 日本-区二区三区免费精品 日本热久久 | 伊人色综合网 | 老司机精品久久 | 国产亚洲欧美在线视频 | 久久久久免费精品视频 | 日韩美女中文字幕 | 久久久青草| 在线视频一区二区三区四区 | 宅男在线影院 | 日韩不卡视频在线 | 精品免费久久久久久影院 | 奇米第四色首页 | 精品一区二区三区四区乱码90 | 91视频地址 | 日本成人中文字幕 | 狠狠插狠狠干 | 精品一区二区三区四区乱码90 | 国产日韩欧美成人 | 99热这里只有精品在线播放 | 成年女人黄小视频 | 日韩不卡一级毛片免费 | 4huh34四虎最新久 | 欧美成人四级剧情在线播放 | 久久国产成人精品国产成人亚洲 | 国产精品久久久久蜜芽 | 国外成人免费视频 | 日本另类αv欧美另类aⅴ | 一级黄色录像视频 | 亚洲精品99久久一区二区三区 | 日韩国产成人精品视频 | 国产精品一区二区久久精品 | 精品国产一区二区三区19 | 精品国产欧美一区二区三区成人 | 婷婷在线综合 | 亚洲欧洲日韩国产一区二区三区 |