我想重新缩放图表,但我真的不知道该怎么做。我设置了缩放,但它解决了我的问题
实际上,绘图上的数据是以小数据显示的
代码看起来像:
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轴值,线形图本身保持稳定
如何重新缩放图形以使其具有良好的可见性?感谢
我通过使用代码行解决了这个问题
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange (1.200, 1.320);
rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits ());
rangeAxis.setTickUnit (new NumberTickUnit(0.005, df, 0));
尤其是最后一行。
感谢所有