0

示例:添加 (0, y1) 点和 (0,0) 然后 (20, 0) 和 (20, y2) 和 (20, 0), 然后 (30,0) 和 (30, y3) 和 (30, 0) 等等,所以总是回到 x 轴和第一步。

还有其他/更好的方法吗?

4

1 回答 1

1

将图表的默认 TracePainter 更改为 TracePainterVerticalBar。

试试这个示例代码:

public class MinimalStaticChart {

  MinimalStaticChart() {
    super();
  }

  public static void main(String[]args){
    // Create a chart:  
    Chart2D chart = new Chart2D();
    // Create an ITrace: 
    ITrace2D trace = new Trace2DSimple();   
    // change to vertical bar diagram
    trace.setTracePainter(new info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar(chart));   
    // Add the trace to the chart. This has to be done before adding points (deadlock prevention): 
    chart.addTrace(trace);    
    // Add all points, as it is static: 
    Random random = new Random();
    for(int i=10;i>=0;i--){
      trace.addPoint(i,random.nextDouble()*10.0+i);
    }
    // Make it visible:
    // Create a frame.
    JFrame frame = new JFrame("MinimalStaticChart");
    // add the chart to the frame: 
    frame.getContentPane().add(chart);
    frame.setSize(400,300);
    // Enable the termination button [cross on the upper right edge]: 
    frame.addWindowListener(
        new WindowAdapter(){
          public void windowClosing(WindowEvent e){
              System.exit(0);
          }
        }
      );
    frame.setVisible(true);
  }
}
于 2014-08-06T15:59:25.490 回答