Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chartjs plugin streaming in angular7 doesnt work #55

Closed
DianPermana opened this issue Dec 8, 2018 · 10 comments
Closed

Chartjs plugin streaming in angular7 doesnt work #55

DianPermana opened this issue Dec 8, 2018 · 10 comments
Assignees
Labels

Comments

@DianPermana
Copy link

Hello sir, I am dian from indonesia, i have tried for chart.js plugin streaming in angular 7, but when I run this plugin (https://nagix.github.io/chartjs-plugin-streaming/ ) doesnt work (not display graph). And then, I have tried chart.js in angulat 7 from "https://valor-software.com/ng2-charts/" it's work. where is the problem, i dont understand. Please can you review this problem.

@nagix
Copy link
Owner

nagix commented Dec 8, 2018

I have confirmed the plugin works with ng2-charts in Angular 7. Click the 'Angular 2+' tab in the tutorial page and follow the instructions.

@nagix nagix self-assigned this Dec 8, 2018
@nagix nagix added the question label Dec 8, 2018
@adripanico
Copy link

I've used it with Angular 6 and I've recently updated to Angular 7 without any issue.

@johndacost
Copy link

johndacost commented Feb 6, 2019

Hi, almost the same problem... I follow this sample.

but onRefresh: function (chart) {...} is never call

  public options: any = {
    scales: {
      xAxes: [{
        type: 'time',
        realtime: {
          duration: 20000,    // data in the past 20000 ms will be displayed
          refresh: 1000,      // onRefresh callback will be called every 1000 ms
          delay: 1000,        // delay of 1000 ms, so upcoming values are known before plotting a line
          pause: false,       // chart is not paused
          ttl: undefined,
          // a callback to update datasets
          onRefresh: function (chart: any) {
            debugger;
            // query your data source and get the array of {x: timestamp, y: value} objects
            var data = [Math.random()];
            // append the new data array to the existing chart data
            Array.prototype.push.apply(chart.data.datasets[0].data, data);
          }
        }
      }]
    },
    plugins: {
      streaming: {            // per-chart option
        frameRate: 30       // chart is drawn 30 times every second
      }
    }

@nagix
Copy link
Owner

nagix commented Feb 7, 2019

@johndacost Do you see any error messages in console?

@adripanico
Copy link

Hi, almost the same problem... I follow this sample.

but onRefresh: function (chart) {...} is never call

  public options: any = {
    scales: {
      xAxes: [{
        type: 'time',
        realtime: {
          duration: 20000,    // data in the past 20000 ms will be displayed
          refresh: 1000,      // onRefresh callback will be called every 1000 ms
          delay: 1000,        // delay of 1000 ms, so upcoming values are known before plotting a line
          pause: false,       // chart is not paused
          ttl: undefined,
          // a callback to update datasets
          onRefresh: function (chart: any) {
            debugger;
            // query your data source and get the array of {x: timestamp, y: value} objects
            var data = [Math.random()];
            // append the new data array to the existing chart data
            Array.prototype.push.apply(chart.data.datasets[0].data, data);
          }
        }
      }]
    },
    plugins: {
      streaming: {            // per-chart option
        frameRate: 30       // chart is drawn 30 times every second
      }
    }

I am not using it this way. I have no realtime property. Try this:

public options: any = {
  scales: {
    xAxes: [{
      type: 'realtime',
    }]
  },
  plugins: {
    streaming: {
      frameRate: 30,
      duration: 20000,
      refresh: 1000,
      delay: 1000,
      onRefresh: (chart: any) => {
        ...
      }
    }
  }
}

@johndacost
Copy link

johndacost commented Feb 7, 2019

@johndacost Do you see any error messages in console?

Nope... no error catched..
Congifuration

  • Angular6
  • ionic4

live.page.module.ts

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    ChartsModule,
    RouterModule.forChild(routes)
  ],
  declarations: [LivePage]
})

export class LivePageModule { }

live.page.html

    <div style="display: block">
      <canvas baseChart [chartType]="'line'" [datasets]="datasets" [options]="options">
      </canvas>
    </div>

live.page.ts

  ...
  import 'chartjs-plugin-streaming';
  ...
  datasets: any[] = [{ data: [] }, { data: [] }];
  options: any = {
    scales: {
      xAxes: [{ type: 'realtime' }]
    },
    plugins: {
      streaming: {
        frameRate: 30,
        duration: 20000,
        refresh: 1000,
        delay: 1000,
        onRefresh: function (chart: any) {
          console.log("test");
          chart.data.datasets.forEach(function (dataset: any) {
            dataset.data.push({
              x: Date.now(),
              y: Math.random()
            });
          });
        },
      }
    }
  };

Package.json

"@types/chart.js": "^2.7.42",
"angular-chart.js": "^1.1.1",
"chart.js": "^2.7.3",
"chartjs-plugin-streaming": "^1.7.1",
"moment": "^2.24.0",
"ng2-charts": "^1.6.0",

Result
image

@johndacost
Copy link

Hi, almost the same problem... I follow this sample.
but onRefresh: function (chart) {...} is never call

  public options: any = {
    scales: {
      xAxes: [{
        type: 'time',
        realtime: {
          duration: 20000,    // data in the past 20000 ms will be displayed
          refresh: 1000,      // onRefresh callback will be called every 1000 ms
          delay: 1000,        // delay of 1000 ms, so upcoming values are known before plotting a line
          pause: false,       // chart is not paused
          ttl: undefined,
          // a callback to update datasets
          onRefresh: function (chart: any) {
            debugger;
            // query your data source and get the array of {x: timestamp, y: value} objects
            var data = [Math.random()];
            // append the new data array to the existing chart data
            Array.prototype.push.apply(chart.data.datasets[0].data, data);
          }
        }
      }]
    },
    plugins: {
      streaming: {            // per-chart option
        frameRate: 30       // chart is drawn 30 times every second
      }
    }

I am not using it this way. I have no realtime property. Try this:

public options: any = {
  scales: {
    xAxes: [{
      type: 'realtime',
    }]
  },
  plugins: {
    streaming: {
      frameRate: 30,
      duration: 20000,
      refresh: 1000,
      delay: 1000,
      onRefresh: (chart: any) => {
        ...
      }
    }
  }
}

I try your solution but still not refresh the graph :(

@adripanico
Copy link

But is it calling to onRefresh method?

@johndacost
Copy link

johndacost commented Feb 7, 2019

But is it calling to onRefresh method?

EDIT
Yes it's working with your solution !

@nagix
Copy link
Owner

nagix commented Mar 21, 2019

Closing as a solution was suggested.

@nagix nagix closed this as completed Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants