score:2
The data format you provided is wrong, you are trying to
data.dataset.data.push
but the data you provided only have X value. you need to reformat it, the data should have the format like this: {x:$(value), y:${value}}
Open the code snippet below in CodeSandbox
import React from "react";
import { Line } from "react-chartjs-2";
import "chartjs-plugin-streaming";
var createReactClass = require("create-react-class");
const data = {
datasets: [
{
label: "Dataset 1",
borderColor: "rgb(255, 99, 132)",
backgroundColor: "rgba(255, 99, 132, 0.5)",
lineTension: 0,
borderDash: [8, 4],
data: []
}
]
};
const options = {
scales: {
xAxes: [
{
type: "realtime",
realtime: {
onRefresh: function() {
data.datasets[0].data.push({
x: Date.now(),
y: Math.random() * 100
});
},
delay: 2000
}
}
]
}
};
export default createReactClass({
displayName: "LineExample",
render() {
return (
<div>
<Line data={data} options={options} />
</div>
);
}
});
score:0
chart
is undefined because it was never defined in React.
Here is an example with React:
onRefresh: function(chart) {
chart.dataset.data.push({
x: Date.now(),
y: Math.random()
});
}
score:1
without a snippet to play with I'd guess that the problem is here
onRefresh: function(chart) {
data.dataset.data.push({
x: Date.now(),
y: Math.random()
});
}
you've pushed the new data to the initial dataset, but at a guess you'll need to push it to the chart itself. looking at the example at:
https://nagix.github.io/chartjs-plugin-streaming/samples/bar-horizontal.html
seems like you should be passing the data directly to the chart
chart.config.data.datasets.forEach(function(dataset) {
dataset.data.push({
x: Date.now(),
y: randomScalingFactor()
});
});
or maybe, (again I'm just guessing where the new data might go without a mvp example to play with, console.log out the chart variable in the onRefresh callback to find the right location), If you setup a mvp on somewhere like stackblitz I/someone can update this answer.
onRefresh: function(chart) {
chart.dataset.data.push({
x: Date.now(),
y: Math.random()
});
}
Source: stackoverflow.com
Related Query
- Graph streaming real-time data with react and chartjs
- Streaming Real-time data with react and chartjs-plugin-streaming paused
- Create a rounded bar graph with Angular and chartJS
- Chartjs real time graph x axis movement
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- Angular 2: How to pass my API data to graph and Display the Graph with data
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How to properly feed data to ChartJS with different number of x(labels) and y(data) points
- Visualization of charts using real time data from MSSQL with node.js webserver
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- How to plot a line graph with x and y data
- Styling background (fill) with ChartJs and React
- Trying to export chart with Chartjs and React but getting erorr
- How to start the chart from specific time and offest hour and then show the data on chart from target datetime in chartjs
- Two data sets with different time instances on the same ChartJs chart
- How I can add the predict data and the actual data in the same graph with ChartJS?
- React and Chartjs not updating from dynamic data through api
- How to display multiple graphs in real time with chartjs
- ChartJS 3.7 data not dynamically updating with data streaming into CSV
- How can I update my ChartJS in real time (It's works only when I zoom-in and zoom-out)
- Issues with Moment and ChartJS Time Format Parsing
- Chartjs create chart with big data and fixed labels
- load a graph with chart.js and react
- ChartJS Tooltips with time axis and multiple datasets
- How to create rounded bar graph with Angular 7 and Chartjs (v2)
- White space at start and end of data with time scale in chart.js
- How to implement doughnut ChartJS with CodeIgniter 3 and display data from database
- Creating a real time line chart using chartjs and firebase realtime db
More Query from same tag
- Angular Charts - not able to read data
- How to add gradient background to Line Chart [vue-chart.js]
- Chart.js v2 is there a way to draw bar chart horizontally?
- Chart.js Increase font size for higher resolution (i.e. monitor-agnostic chart configuration )
- chartJSRadar downloadhandler creating empty png
- Chart: Two bipolar bars below each other
- Not able to show data on Chart.js
- chart.js charts wouldn't show or hide with Angular directives ng-show and ng-hide
- Chart.js tooltip background color setting
- Moving vertical line when hovering over the chart using chart.js
- How to change colour of specific xAxis label in charts js
- How to show labels above pie chart in chart.js
- Pie Charts JS: How to set units?
- Bold text inside doughnut chart (chart.js)
- ChartJS donut chart clipping the edges
- How to add text at end of each line in charts.js
- syntax error, unexpected ' ' Laravel 5.6 ConsoleTvs chart js
- Legend for only specific datasets - chart.js
- Chart.js - access yAxes properties
- How to I optimise these javscript options which is used multiple times on different chart.js graphs?
- Add mouseout event handler to legends in Chart.js
- ChartJs line chart - display permanent icon above some data points with text on hover
- Chart.js BarChart not appearing
- ChartJS line chart drag and zoom
- Which jquery plugin can create a stacked column chart?
- How to append more data in tooltip of graph in chart.js
- How To get keys(index) of collection in laravel
- How to Add X axis Padding in chart js Line Graph
- Chartjs-gauge create circumference until certain value from data
- ChartJS – is there any way to remove blank space around pie charts?