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).

!7

lib 1400104 // XChart

import org.knowm.xchart.*;

sclass XChartRealTimeTest > DynModule {
  transient double phase = 0;
  
  JComponent visualize() {
    double[][] initdata = getSineData(phase);

    // Create Chart
    final XYChart chart = QuickChart.getChart("Simple XChart Real-time Demo", "Radians", "Sine", "sine", initdata[0], initdata[1]);

    final JComponent panel = new XChartPanel(chart);
    awtEvery(panel, 200, r {
      phase += 2 * Math.PI * 2 / 20.0;
      double[][] data = getSineData(phase);

      chart.updateXYSeries("sine", data[0], data[1], null);
      revalidate(panel);
    });
    ret panel;
  }

  double[][] getSineData(double phase) {
    double[] xData = new double[100];
    double[] yData = new double[100];
    for i over xData: {
      double radians = phase + (2 * Math.PI / xData.length * i);
      xData[i] = radians;
      yData[i] = Math.sin(radians);
    }
    ret new double[][] { xData, yData };
  }
}

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: 431 / 564
Version history: 4 change(s)
Referenced in: [show references]