JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Tools  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請教 JFreeChart TimeSeries 的間隔設定
bradlee7321





發文: 32
積分: 0
於 2003-07-30 12:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我用JFreeChart做出一個TimeSeries...
可是它的點與點之間因為從資料庫抓出來的時間並沒有連續
所以間隔有些很大, 有些擠在一起甚至同一天的會在同一條線
請問我要怎麼在X軸上把它們的點與點之間的間隔設成一樣
我用的版本是v0.9.8
================================================
  String chartTitle = "Multi X Chart";  
  JFreeChart chart = ChartFactory.createTimeSeriesChart(
      chartTitle,
      time, "KA",
      dataset,
      true,
      true,
      false
      );
      
  StandardLegend sl = (StandardLegend) chart.getLegend();
  sl.setDisplaySeriesShapes(true);
  
  XYPlot plot = chart.getXYPlot();
  XYItemRenderer renderer = plot.getRenderer();
  if (renderer instanceof StandardXYItemRenderer) {
  StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
      rr.setPlotShapes(true);
      rr.setDefaultShapeFilled(true);
      }
      
  DateAxis axis = (DateAxis) plot.getDomainAxis();
  axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
    
  /*
  ChartPanel chartPanel = new ChartPanel(chart);
  chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
  chartPanel.setMouseZoomable(true, false);
  setContentPane(chartPanel);
  */
  
  chart.setBackgroundPaint(java.awt.Color.white);
  
  OutputStream ostream = response.getOutputStream();
  ChartUtilities.writeChartAsPNG(ostream, chart, 700, 400);
  ostream.close();
================================================


browser edited on 2003-07-30 13:29
reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2003-07-30 12:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我想先請教你
你之前問題怎樣解決的??
解決問題應該回來分享一下巴?
總是問問題,偶爾也該說明一下你怎樣解決了之前的問題巴
你之前的tooltip顯示到底錯在哪??
不知能否請大大分享一下???

koji


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
bradlee7321





發文: 32
積分: 0
於 2003-07-30 12:34 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
阿阿....
之前的問題我還沒找出來...>"<
我找到問題後一定會po出來的.....


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2003-07-30 13:16 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我覺得這個要求有點難等於你下面的range都會不一樣
我現在測試找不到可以改到的地方
不然你試試看ZOOM,依狀況去放大某一區塊
要整各圖的x軸range大小不同好像有點難>.<
我再試試看
如果你知道以後也分享一下

good luck

koji


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
bradlee7321





發文: 32
積分: 0
於 2003-07-30 13:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
嗯嗯, 感謝koji大大
我自己在試試看...
不然就要另外想辦法做到類似的效果了~~~


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2003-07-30 13:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
突然想到
你要不要試試看linechart
它可以自己定XY軸的名稱等等
你就可以每個資料都各自定義

http://www.jsp.mlc.edu.tw
它的統計圖一
你看一下最下面的linechart
它上面雖然是0.9.4
但是我想如果要做應該可以
不知這些資訊夠不夠了

koji


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
bradlee7321





發文: 32
積分: 0
於 2003-07-30 13:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
呵呵...
我剛剛也忽然想到, 正在試中...^__^
等可以後我再把程式po出來
感謝koji哩


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
bradlee7321





發文: 32
積分: 0
於 2003-07-30 15:39 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Hi, koji大....
我用LineChart試了一下
本來應該只會有11個點, 可是圖形卻出現了12個點
圖形的情形還是一樣, 間隔還是很大, 可能是我太笨了, x軸不知道怎麼設定..@@"
而且x軸的日期格式變得很怪, 不知道是啥...
================================================
  JDBCXYDataset dataset = new JDBCXYDataset(con);
  String sql="SELECT REVDATE,AVG(numericvalue) FROM PLLDBA.TRES_RAWDATA WHERE lotid IN (SELECT DISTINCT lotid FROM PLLDBA.TRES_RAWDATA WHERE TESTOPNO='"+Sdcop+"' AND to_char(REVDATE,'yyyy/mm/dd') between '"+Sstartdate+"' AND '"+Senddate+"' ) and testopno='"+Sdcop+"' AND to_char(REVDATE,'yyyy/mm/dd') between '"+Sstartdate+"' AND '"+Senddate+"' GROUP BY lotid,revdate order by REVDATE";
  dataset.executeQuery(sql);
  
  String chartTitle = "Multi X Chart";
  JFreeChart chart = ChartFactory.createLineXYChart(
      chartTitle, // chart title
      time, // x axis label
      "KA", // y axis label
      dataset, // data
      true, // include legend
      true, // tooltips
      false // urls
      );

  chart.setBackgroundPaint(java.awt.Color.white);
  
  XYPlot plot = chart.getXYPlot();
  
  StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
  renderer.setPlotShapes(true);
  renderer.setDefaultShapeFilled(true);
  
  NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
  rangeAxis.setAutoRangeIncludesZero(false);
  
  OutputStream ostream = response.getOutputStream();
  ChartUtilities.writeChartAsPNG(ostream, chart, 700, 400);
  ostream.close();
================================================


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
bradlee7321





發文: 32
積分: 0
於 2003-07-31 09:45 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Hi koji大~~~
我用LineChart做出比較類似的...
用的方式比較奇怪一點~~~先用Resultset先把資料篩選出來
然後X軸先自行用程式迴圈的編號產生
可是我如果想在小紅點上ToolTip加上日期的話, 可能做到嗎?
因為我看範例目前只看到dataset裡面要有東西ToolTip才會跟著有...
請指教~~~^__^
================================================
  String sql = "SELECT lotid,REVDATE,AVG(numericvalue) FROM PLLDBA.TRES_RAWDATA WHERE lotid IN (SELECT DISTINCT lotid FROM PLLDBA.TRES_RAWDATA WHERE TESTOPNO='ZP9V1.01' AND revdate > TO_DATE('2003/07/14 00:00:00','YYYY/MM/DD HH24:MI:SS') and revdate < TO_DATE('2003/07/26 00:00:00','YYYY/MM/DD HH24:MI:SS') ) and testopno='ZP9V1.01' AND revdate > TO_DATE('2003/07/14 00:00:00','YYYY/MM/DD HH24:MI:SS') and revdate < TO_DATE('2003/07/26 00:00:00','YYYY/MM/DD HH24:MI:SS') GROUP BY lotid,revdate order by REVDATE";
  ResultSet rs = stmt.executeQuery(sql);
        
  rs.last();
  int total=rs.getRow();
  rs.beforeFirst();
          
  XYSeries series1 = new XYSeries("AVG(NUMERICVALUE)");
  
  for (int i=1;i<=total;i++)
  {      
    rs.next();
    float AVG = rs.getFloat("AVG(numericvalue)");
    series1.add(i, AVG);  
  }
  
  XYSeriesCollection dataset = new XYSeriesCollection();
  dataset.addSeries(series1);

  rs.close();
  stmt.close();
  
  String charttitle="Multi X Chart";
  JFreeChart chart = ChartFactory.createLineXYChart(
      charttitle,
      "INDEX",
      "KA",
      dataset,
      true,
      true,
      false
      );

  chart.setBackgroundPaint(java.awt.Color.white);
  
  XYPlot plot = chart.getXYPlot();
  StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
  renderer.setPlotShapes(true);
  renderer.setDefaultShapeFilled(true);
  
  NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
  rangeAxis.setAutoRangeIncludesZero(false);
  rangeAxis.setMaximumAxisValue(4.2);
  rangeAxis.setMinimumAxisValue(3.4);
  
  OutputStream ostream = response.getOutputStream();
  ChartUtilities.writeChartAsPNG(ostream, chart, 700, 400);
  ostream.close();
================================================


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
smartdanny





發文: 598
積分: 1
於 2005-06-28 14:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問為什麼我會出現
java.lang.ClassCastException at JFreeAreaChartTest.initAreaChart(JFreeAreaChartTest.java:79)
at JFreeAreaChartTest.<init>(JFreeAreaChartTest.java:35)
at JFreeAreaChartTest.main(JFreeAreaChartTest.java:90)

顯然是這行錯誤~為什麼你的程式可以run而我的會出現Exception呢?
DateAxis axis = (DateAxis) plot.getDomainAxis();


reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:bradlee7321]
freshia77





發文: 32
積分: 0
於 2005-10-06 17:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
大家好...這是我參考各位的文章所寫的,
不過下面日期的部分一直改不好,
麻煩各位大大指導一下嚕....謝謝^^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<%@page contentType="image/jpeg;charset=MS950"%> 
<!--因為要顯示圖形,設定contentType為image/jpeg --> 
<%@page import="java.util.*,java.io.*,java.awt.*,java.text.*"%> 
<%@page import="org.jfree.data.category.*"%> 
<%@page import="org.jfree.data.general.*"%> 
<%@page import="org.jfree.data.*"%> 
<%@page import="org.jfree.data.xy.*"%> 
<%@page import="org.jfree.chart.*"%> 
<%@page import="org.jfree.chart.axis.*"%> 
<%@page import="org.jfree.chart.ui.*"%> 
<%@page import="org.jfree.chart.plot.*"%> 
<%@page import="org.jfree.chart.renderer.xy.*"%> 
<%@ page import="org.jfree.ui.ApplicationFrame"%> 
<%@ page import="org.jfree.ui.RefineryUtilities"%> 
<%@ page import="org.jfree.chart.title.*"%> 
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%> 
<%@ page import="org.jfree.chart.urls.*"%> 
<%@ page import="org.jfree.chart.entity.*"%> 
<%@ page import="org.jfree.chart.labels.StandardXYToolTipGenerator"%> 
<% 
    XYSeries series1 = new XYSeries("30");
 
    for (int i=1;i<=15;i++) 
    {       
        series1.add(i, 30+i);   
    } 
   
    XYSeriesCollection dataset = new XYSeriesCollection(); 
    dataset.addSeries(series1); 
 
    String chartTitle = "Multi X Chart";   
    JFreeChart chart = ChartFactory.createTimeSeriesChart( 
      chartTitle, 
      "time", "KA", 
      dataset, 
      true, 
      true, 
      false 
      ); 
       
    chart.setBackgroundPaint(java.awt.Color.white);  
 
    XYPlot plot = chart.getXYPlot(); 
    XYItemRenderer renderer = plot.getRenderer(); 
    if (renderer instanceof XYLineAndShapeRenderer) 
    {
        XYLineAndShapeRenderer rr = (XYLineAndShapeRenderer) renderer;
        rr.setDefaultShapesVisible(true);
        rr.setDefaultShapesFilled(true);
 
    } 
       
    DateAxis axis = (DateAxis) plot.getDomainAxis(); 
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd")); 
    
    
     
    /* 
    ChartPanel chartPanel = new ChartPanel(chart); 
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); 
    chartPanel.setMouseZoomable(true, false); 
    setContentPane(chartPanel); 
    */ 
   
    //chart.setBackgroundPaint(java.awt.Color.white); 
   
    OutputStream ostream = response.getOutputStream(); 
    ChartUtilities.writeChartAsPNG(ostream, chart, 700, 400); 
    ostream.close(); 
%> 
<img src="timeserieschart.jsp">



freshia77 edited on 2005-10-07 15:42
reply to postreply to post
作者 Re:請教 JFreeChart TimeSeries 的間隔設定 [Re:freshia77]
blueway2002





發文: 11
積分: 0
於 2007-05-10 23:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的jfreechart版本是0.9.21
請教一下,就是有關畫出來的褶線圖,要如何修正它的範圍,讓曲線不會起伏太大,多謝回答!!


reply to postreply to post
» JWorld@TW »  Java Tools

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8