Comments (4)
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.
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.
@nagix could i just use ng2-charts instead of using chart.js ?
from chartjs-plugin-streaming.
The Angular sample in this tutorial is using ng2-charts (which depends on Chart.js, though).
from chartjs-plugin-streaming.
Related Issues (20)
- Page is blank when making React App with tutorial HOT 1
- Realtime streaming from left to right
- Vue.js renderChart undefined
- Streaming for non timebased data HOT 1
- Problem with types
- How to reset the x axies lables with minite
- Failed to initialize NumberFormat since used feature is not supported in the linked ICU version on Ubuntu
- Need axis scale as "realtime" with "timeserias" properties
- Websocket question HOT 1
- Can't change x axis time format from AM / PM to 24 hour clock
- TypeError after unmounting chart HOT 22
- Any State Changes triggers re render and loss of data HOT 2
- when I toggle chartjs streaming, streaming configurations still working.
- Stream to the right side, start plotting from the left side
- Plans to update for ChartJS 4.x? HOT 11
- Chartjs Line chart streaming stops when browser tab is not active HOT 1
- Change spacing between ticks on x-axis?
- Styling: left, right, and yAxis line color? HOT 1
- Streaming Moves Rapidly Left when Duration of Graph is Full of Data HOT 4
- TypeError: Cannot read properties of undefined (reading 'getDatasetMeta')
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chartjs-plugin-streaming.