Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1016878 // XChart RealTime Test [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 0K of libraries. Click here for Pure Java version (4621L/30K).

1  
!7
2  
3  
lib 1400104 // XChart
4  
5  
import org.knowm.xchart.*;
6  
7  
sclass XChartRealTimeTest > DynModule {
8  
  transient double phase = 0;
9  
  
10  
  JComponent visualize() {
11  
    double[][] initdata = getSineData(phase);
12  
13  
    // Create Chart
14  
    final XYChart chart = QuickChart.getChart("Simple XChart Real-time Demo", "Radians", "Sine", "sine", initdata[0], initdata[1]);
15  
16  
    final JComponent panel = new XChartPanel(chart);
17  
    awtEvery(panel, 200, r {
18  
      phase += 2 * Math.PI * 2 / 20.0;
19  
      double[][] data = getSineData(phase);
20  
21  
      chart.updateXYSeries("sine", data[0], data[1], null);
22  
      revalidate(panel);
23  
    });
24  
    ret panel;
25  
  }
26  
27  
  double[][] getSineData(double phase) {
28  
    double[] xData = new double[100];
29  
    double[] yData = new double[100];
30  
    for i over xData: {
31  
      double radians = phase + (2 * Math.PI / xData.length * i);
32  
      xData[i] = radians;
33  
      yData[i] = Math.sin(radians);
34  
    }
35  
    ret new double[][] { xData, yData };
36  
  }
37  
}

Author comment

Began life as a copy of #1016877

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, vouqrxazstgt

No comments. add comment

Snippet ID: #1016878
Snippet name: XChart RealTime Test [Dyn Module]
Eternal ID of this version: #1016878/5
Text MD5: 3402bce4e21210a71081e44b5c0d124f
Transpilation MD5: 9b01c2b3506c0ae6647277c96c65e72a
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-14 17:13:27
Source code size: 990 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 433 / 567
Version history: 4 change(s)
Referenced in: [show references]