Git Product home page Git Product logo

Comments (4)

nagix avatar nagix commented on July 16, 2024 2

Ok, it works with Angular 5. Import modules this way:

import {Component, ElementRef, OnInit, AfterViewInit} from '@angular/core';
import {Chart} from 'chart.js';
import 'chartjs-plugin-streaming';
import moment = require('moment');

from chartjs-plugin-streaming.

AtifJaved1 avatar AtifJaved1 commented on July 16, 2024
import {Component, ElementRef, OnInit, AfterViewInit} from '@angular/core';
import * as Chart from "chartjs-plugin-streaming";
import moment = require("moment");

@Component({
  selector: 'app-stats',
  templateUrl: './stats.component.html',
  styleUrls: ['./stats.component.css']
})


export class StatsComponent implements AfterViewInit {


  canvas: any;
  ctx: any;


  constructor() {

  }

  ngAfterViewInit() {
    this.canvas = document.getElementById('myChart');
    this.ctx = this.canvas.getContext('2d');

    var chartColors = {
      red: 'rgb(255, 99, 132)',
      orange: 'rgb(255, 159, 64)',
      yellow: 'rgb(255, 205, 86)',
      green: 'rgb(75, 192, 192)',
      blue: 'rgb(54, 162, 235)',
      purple: 'rgb(153, 102, 255)',
      grey: 'rgb(201, 203, 207)'
    };

    function newDate(ms) {
      return moment().add(ms, 'ms');
    }

    function randomScalingFactor() {
      return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
    }

    // function onRefresh() {
    //   config.data.datasets.forEach(function (dataset) {
    //     dataset.data.push({
    //       x: moment(),
    //       y: randomScalingFactor()
    //     });
    //   });
    // }

    // var config = ;
    let myChart = new Chart(this.ctx, {
      type: 'line',
      data: {
        labels: [1500, 1600, 1700, 1750, 1800, 1850, 1900, 1950, 1999, 2050],
        datasets: [{
          data: [86, 114, 106, 106, 107, 111, 133, 221, 783, 2478],
          label: "Africa",
          borderColor: "#3e95cd",
          fill: false
        }, {
          data: [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267],
          label: "Asia",
          borderColor: "#8e5ea2",
          fill: false
        }, {
          data: [168, 170, 178, 190, 203, 276, 408, 547, 675, 734],
          label: "Europe",
          borderColor: "#3cba9f",
          fill: false
        }, {
          data: [40, 20, 10, 16, 24, 38, 74, 167, 508, 784],
          label: "Latin America",
          borderColor: "#e8c3b9",
          fill: false
        }, {
          data: [6, 3, 2, 2, 7, 26, 82, 172, 312, 433],
          label: "North America",
          borderColor: "#c45850",
          fill: false
        }
        ]
      },
      options: {
        title: {
          display: true,
          text: 'World population per region (in millions)'
        },
        scales: {

          xAxes: [{
            type: 'realtime',
            display: true,
            scaleLabel: {
              display: true,
              labelString: 'Time'
            }
          }],
          yAxes: [{
            ticks: {
              beginAtZero: true
            },
            scaleLabel: {
              display: true,
              labelString: '° C'
            }
          }]
        },
        plugins: {
          streaming: {
            duration: 1600000,


            // Sending the request for new data loopup is set to 5 mintues
            refresh: 300000,

            delay: 16000,
          }
        }
      }
    });


  }


}

I have attached that code. The error shows is the images attached in the previous post.

from chartjs-plugin-streaming.

itshazlan avatar itshazlan commented on July 16, 2024

@nagix could i just use ng2-charts instead of using chart.js ?

from chartjs-plugin-streaming.

nagix avatar nagix commented on July 16, 2024

The Angular sample in this tutorial is using ng2-charts (which depends on Chart.js, though).

from chartjs-plugin-streaming.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.