2012-08-31 79 views
0


我想重新調整圖表,但我真的不知道要這樣做。我設置了縮放,但它解決了我的問題。
事實上,圖中的數據以小數據顯示。
代碼看起來像:
JFreeChart,如何重新調整y軸

public class DrawChart { 

private static final Random random = new Random(); 
RefreshGraph refresh; 

public DrawChart(JPanel panel){ 
    this.refresh = new RefreshGraph(); 
    this.displayChart (panel); 
} 

private void displayChart(JPanel jpanel){ 
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 

    Timer timer = new Timer(1000, new ActionListener(){ 
     @Override 
     public void actionPerformed(ActionEvent e){ 
      refresh.getRefresh (dataset); 
     } 
    }); 
    timer.start(); 

    JFreeChart chart = createChart(dataset); 

    ChartPanel panel=new ChartPanel(chart); 
    panel.setPreferredSize (new Dimension(700,300)); 
    jpanel.setLayout(new java.awt.BorderLayout()); 
    jpanel.add (panel, BorderLayout.CENTER); 
    jpanel.setVisible(true); 
} 

private JFreeChart createChart(final CategoryDataset dataset){ 
    final JFreeChart result = ChartFactory.createLineChart ("", null, null, dataset, PlotOrientation.VERTICAL, true, true, false); 

    //Set the background color for the chart 
    result.setBackgroundPaint (Color.white); 

    //get the plot for customization 
    final CategoryPlot plot = result.getCategoryPlot(); 
    plot.setBackgroundPaint(Color.lightGray); 
    plot.setDomainGridlinePaint(Color.white); 
    plot.setRangeGridlinePaint(Color.white); 
    plot.zoom (0.5); 

    CategoryAxis domainAxis = plot.getDomainAxis(); 
    final IntervalMarker target = new IntervalMarker(0.25, 1.0); 

    //This thread will read the tempory file every minutes and refresh the graph 
    Timer timer = new Timer(5000, new ActionListener(){ 
     public void actionPerformed(ActionEvent e){ 
      boolean eof_=false; 
      try{ 
       File labelingraph = new File(System.getProperty("user.dir")+"\\period.in"); 
       if(labelingraph.exists()){ 
        BufferedReader readPeriod = new BufferedReader(new FileReader(labelingraph)); 
        while(eof_!=true){ 
         String _line = readPeriod.readLine(); 
         if(_line!=null){ 
          target.setLabel("Period : "+_line); 
         }else{eof_=true;} 
        } 
       } 
      } 
      catch(IOException io){System.out.println ("Error while accessing the file : "+io.getMessage());} 
     } 
    }); 
    timer.start(); 

    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); 
    target.setLabelAnchor(RectangleAnchor.LEFT); 
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); 
    target.setPaint(new Color(222, 222, 255, 128)); 
    plot.addRangeMarker(target, Layer.BACKGROUND); 

    return result; 
}} 

變焦僅縮小的y軸的值和行圖本身保持穩定。
如何重新調整圖表以使其具有良好的可見性? 感謝

+0

可能的複製[此](http://stackoverflow.com/q/11869704/230513)和[此](http://stackoverflow.com/q/11693929/230513) 。請編輯您的問題,以包含展示您描述的問題的[sscce](http://sscce.org/)。 – trashgod

+0

此[鏈接](http://stackoverflow.com/q/11869704/230513)和此[鏈接](http://stackoverflow.com/q/11693929/230513)已解決。 – DeathCoder

+0

優秀;請刪除此問題或將其編輯爲包含顯示您描述的問題的[sscce](http://sscce.org/)。 – trashgod

回答

0

我用代碼

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 
rangeAxis.setRange (1.200, 1.320); 
rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); 
rangeAxis.setTickUnit (new NumberTickUnit(0.005, df, 0)); 

尤其是最後一行的這些線路解決了這個。

由於所有