Giter VIP home page Giter VIP logo

chartjs-plugin-streaming's People

Contributors

alx avatar nagix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chartjs-plugin-streaming's Issues

Performance issue

When the number of charts is over around 15, the frame rate goes down 10(7-8) and the screen seems ugly. I've tested out with your samples by adding the same chart over 20 and it also gets too slow. Is there any performance handling workaround other than you specified on README?

How to set the max y according to the realtime data?

I'd like to reset the max ticks of yAxes dynamically when based on the realtime data. I tried implementing it as following:

// Angular 5+
// When the new data arrives,
// data: number[]
this.chartObj.config.options.scales.yAxes[0].ticks.max = Math.max(...data) >= 5 ? undefined : 5; // 5: default Y max value

But if the new data's max value is 3, for example, the max Y sets as 5 and if the previous max value is 8 and the data is still drawn on the chart, the result is not right. So my question is, how can I figure out the max data on the chart area so that I could set the max Y accordingly?

Many thanks!

Realtime chart makes 'time' charts become realtime charts

Hi,

I'm having some issues placing both a chart of x-axis type 'time' along with a realtime chart.

It seems like the 'time' chart is being overruled by the realtime x-axis even if the x-axis is set to 'time', making both charts realtime charts.

Is there something that I may be missing?

Thanks again for a great chartjs plugin!

Data points vanish on duration changes

Hello, I'd like to report a bug, But maybe it's a feature and designed behaviour,

After dynamic changing duration from bigger to smaller and to bigger again some points in the beggining of chart dissapears,

It can be repriduced on samle with interactions - https://nagix.github.io/chartjs-plugin-streaming/samples/interactions.html

Steps:

  1. Set max duration - 60000 ms
  2. Note the first point values
  3. Wait a bit - 5-10 seconds.
  4. Set min duration - 1000 ms

Actual:
Points that appeared between max and min duration change are lost.

Expected:
All points are preserved.

If you need any help from my side to fix this, please let me know.

Smooth scale changes

When Chart.js rescales to fit the data in the chart within the y-axes, it does so rather abruptly (as seen here). Ideally, the transition should be smooth, similar to Smoothie Charts.

Streaming + zoom not function

Hi, (sorry for my english)
i use chartjs-plugin-streaming for the real time chartjs and i want to use the chartjs-plugin-zoom.
But when i try to zoom, nothing happens.
I see that the 'doZoom' method of 'chartjs-plugin-zoom' is called, but when it called 'update method nothing happens.
I tested to call pause of the streaming before to do the zoom but there is the same problem...

What can I do to make the zoom work?

Thank for now...

Scrollbar along X-axis?

Is there a way to show a scroll bar along X-axis (time) so we can still see the old data that have already disappeared off the chart?

Using Firebase

Can you please help me with some code to show how can I use this plugin to fetch realtime data from Firebase and show in graph? The structure is like this:
screen shot 2018-08-29 at 10 32 04 am

Angular 5

Hi, your plugin looks wonderful. How can I use it with angular 5? Can you please show me a simple example?
screen shot 2018-02-25 at 11 32 32 pm

this is the error I am facing

Able to stop chart from scrolling (pause)

Hello,

I've been using your plugin for a week and it's awesome. I am currently investigating ways on "pausing" the chart scrolling, stopping all updates to the chart data at the same time. Stopping the Ingress of data is easy, but I can't find a straightforward way to stop the automatic scrolling of the chart so I can peruse a subset of the data without it vanishing on me.

Please advise.

Thanks in advance,

Jordan

With `pause: true` without setting `ttl`, old data is not removed

The documentation for ttl says:

If not set, old data will be automatically deleted as it disappears off the chart.

If the chart is paused the old data is not removed. This correct according to the documentation because technically, the data does not disappear off the chart when paused as the chart isn't moving.

However if paused for a long time and there is a lot of new data, and then resuming, the browser can freeze until the old data is removed. This is also bad memory wise.

I expected it to follow the duration option (+ x to be sure it is off the chart and doesn't affect interpolation), but appears to be using the scale. The scale is not changing when paused.

I'm not sure what the best solution would be. Either way, checking for old data when paused (without having set ttl) doesn't do anything useful since scale.left doesn't change when paused. So currently that's just wasted cpu.

As a workaround I'm currently setting ttl to duration + 5000.

ps: awesome plugin btw. great work

Keeping scales in sync across multiple graphs (or dynamically changing scales)

Here's my use case: I have two charts, one on top of the other, as seen here. Ideally, they'd be two datasets in a single chart, but I couldn't come up with a way to start one chart halfway through the other (especially with the streaming delay). Regardless, both datasets should have the same scale max and min.

I could manually give them the same ticks: { min, max} on creation, but the range of values in my dataset is too large to set them once at the beginning and leave them. So, I have to let chart.js figure out the scales for me based on the data currently in the chart. But since both lines have slightly different data, the generated scales vary slightly, and you can see them rescale at different times in the gif above.

I've tried setting the parent component's state with the larger chart's chart.scales["y-axis-0"].max and min from within the options: plugins: streaming: onRefresh: function, and then trying to set the other chart's values from that state within its onRefresh. But the second chart seems to be ignoring the updated values (or the values I'm setting don't actually control the scale).

So, what is the best way to keep scales in sync across multiple charts?

Cordova Projects

this plugin dont works with cordova based projects.

Screenshot for PC
localhost_8001_main html iphone 5_se

Screenshot for Mobile
0a9132e8-5782-46dd-8d1c-982c855f84b7

Start right away with a delay

In my case I have a slow stream that updates every 5 seconds which i've specified with the delay property. The problem with this is that the data will be fetched after 5 seconds so my users have to wait 5 seconds before they can read the chart. The data is available right away, so is there an option that I can start immediately instead of waiting 5 seconds or preloading that data somehow?

Chartjs Plugin Streaming does not have callback function to append array of data into chart

When using websocket or other forms of data streaming, chart should be refreshed with sampled data periodically. In this case we need two dimensional array (e.g. 2DArray=[{time, A1,A2,A3,...}) and push it to the chart.
It seems chartjs-plugin does not accept array (chart.data.datasets[j].data.push(data[i][j]);)
Your help greatly appreciated for a working example.

Thanks

Preload data

Is there a way to preload data to the left of the chart? For example historical data that does not need to be streamed in.

Multi-Datasets Chart streaming with pause

You provided a great facility for data streaming but the examples are having the same format. Could you please add an multi datasets (time,A1,A2,A3,A4) chart with pause key in the chartjs-plugin-streaming repository. Thank you

How to automatic display tooltips

Hi,
I'm working on streaming chartjs and trying to display the tooltip of the newest updating point. How can i do it without using 'mousehover'

afterInit onRefresh Timer

I'm running into issues with the React lifecycle, where the chart instance is being destroyed and recreated, leaving the exisitng afterInit() plugin timer hanging around. Multiple timers get spun up because of this.

I recommend to cancel that timer in the destroy() plugin hook as a best practice.

    afterInit: function(chart, options) {
        refreshTimerId = setInterval(function() {
            onRefresh(chart);
        }, options.refresh);
    },

    destroy: function(chart, options) {
        clearInterval(refreshTimerId);
    },

How to create very fast Chart

I understand current limitation of x axis (only accept time format) but I guess with refreshing delay and colors can make it faster to display 1000 hz sampling rate streaming data.
Please advice.

Thanks

Support for different time zones

It could be nice if you were able to set a different time zone then one the client is currently in.

Any hints on how to make this possible?

Streaming from left to right

Couldnt find any options to stream the charts from left to right instead of right to left. Is there any way to realize that without doing code changes to the plugin?

Error on destroy()

Hi,

Thank you for the quick fix yesterday!

I think the fix might have introduced a new bug.

See the error below on destroy()

image

Minimizing page stops streaming

I'm currently using this plugin to display data I'm polling from a server through ajax.

The asynch ajax method pushes data to an array, and the onRefresh method of the plugin pops it from the array and renders the point.

My problem is that when I minimize the tab, the onRefresh method stops firing (also observable on your demo web-page).

My question (or perhaps feature request) is for the onRefresh method to be called even when the page is minimised.

Can you also recommend a better pattern for using your chart to load datapoints polled from a server through ajax?

Pie charts are broken on page including chartjs-plugin-streaming

When a pie chart is present on a page including chartjs-plugin-streaming, I got the following errors:

Uncaught TypeError: Cannot read property 'xAxes' of undefined
chartjs-plugin-streaming.min.self-Uncaught TypeError: Cannot read property 'getScaleForId' of null

Stream Past Data

Hi, I want to know if there is a way to stream past data. Here are the details:

  • I receive a past data array which is gathered in the backend from date1 to date1. (Both date1 and date2 are past dates)

  • I want to stream the data array from the beginning to the end.

Thanks a lot!

Charts dataset loosing data when datalabels plugin is being used

I've setup a horizontal bar chart to draw a bar based on data pushed to the graph. When I add the data labels plugin into my chart the line is animated and then disappears with the length of the dataset always being erased. If I remove the data labels plugin from the graph the values will chart correctly, but only until the second data_value is pushed onto the dataset, it skips the first one for some reason (maybe a separate bug).

Library versions:
"chart.js": "^2.7.2",
"chartjs-plugin-datalabels": "^0.4.0",
"chartjs-plugin-streaming": "^1.7.0",

Below is my react component:

<HorizontalBar
          ref='chart'
          data={{
            datasets: [{
              label: 'Depth',
              backgroundColor: '#305c8a',
              borderColor: '#305c8a',
              data: []
            }]
          }}
          height={700}
          options={{
            title: {
              display: false
            },
            maintainAspectRation: false,
            tooltips: {
              enabled: false
            },
            legend: {
              display: false
            },
            plugins: {
              datalabels: {
                display: (ctx) =>{
                  var val = ctx.dataset.data[ctx.dataIndex];
                  return val.depth % 5 == 0;
                },
                anchor: 'end',
                align: 'right',
                clip: true,
                formatter: (value, ctx) => {
                  return `${Formatter.formatNumber(value.depth)}'`;
                }
              }
            },
            scales: {
              xAxes: [{
                ticks: {
                  display: false,
                  min: 0,
                  max: 2
                },
                gridLines: {
                  display: false
                }
              }],
              yAxes: [{
                type: 'realtime',
                maxBarThickness: 3,
                gridLines: {
                  display: true
                },
                realtime: {
                  duration: 300000/*14400000*/,
                  delay: 1000,
                  onRefresh: (chart) => {
                    chart.data.datasets[0].data.push({x: 1, y: Date.now(), depth: 1200});
                  }
                }
              }]
            }
          }}
        />

Feature-req: Perf options

The graphs produced by this plugin are very beautiful, but they use a lot of cpu, are there any, or could there be any configurable perf options; perhaps make the animation less fluid at the cost of cpu cycles?

No x axis ticks or labels

I'm unable to get x axis ticks or labels to render like they do in the tutorial. I copied and pasted from the source of your tutorial and created a jsfiddle to demonstrate the issue.

Create array of data and then refresh chart

Is there a way to refresh chart periodically when data is coming fast from a client in a lets say Inputmessage() and can save data on a two dimensional array (Data[row][column])?

Always Draw points from last data point

Let's say the I refresh values after every 5 minutes. But sometimes there will be no value. The last point is just pass and not showing on the graph. Say after 20 minutes I have a new value to be added. The issue is not that the new values are linked to the last shown values that were 20 minutes ago. Though it doesn't have to link to that point whose time is passed.
screen shot 2018-02-04 at 2 33 37 am

Error on calling destroy()

Hi,

I get following error message when calling destroy() on a graph using this plugin

image

Thanks for a great project!

Unable to assign a time offset for x axis labels

We have a datastream that at the current time feeds in data from 5 minutes ago. The x axis labels refuse to change. In the examples, they use Date.now(). Using any form of Date object manipulation or moment functions, it is not allowing the offset to occur. See here for methods we have tried: https://stackoverflow.com/questions/674721/how-do-i-subtract-minutes-from-a-date-in-javascript

It moves the data off screen and we would have to have an absurd duration to see it. Instead, we want to adjust the value of the recent time feeding in as shown in the xaxis labels.

In the docs here you can see the following:

Note that the following options are ignored for the 'realtime' scale.

bounds
distribution (always 'linear')
**offset (always false)**

There is no reason why offset should always be false. Let it be default to false, but do not ignore this field. If I specifically set an offset, please use that value.

gulp build error

I get the following gulp build error for the streaming plugin:

gulp build
[22:47:25] Using gulpfile ~/node_modules/chartjs-plugin-streaming/gulpfile.js
[22:47:25] Starting 'build'...
options.entry is deprecated, use options.input
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Unexpected key 'moduleName' found, expected one of: acorn, amd, banner, cache, context, entry, exports, extend, external, file, footer, format, globals, indent, input, interop, intro, legacy, moduleContext, name, noConflict, onwarn, output, outro, paths, plugins, preferConst, pureExternalModules, sourcemap, sourcemapFile, strict, targets, treeshake, watch
    at validateKeys (/home/sboyls/node_modules/chartjs-plugin-streaming/node_modules/rollup/dist/rollup.js:171:11)
    at checkInputOptions (/home/sboyls/node_modules/chartjs-plugin-streaming/node_modules/rollup/dist/rollup.js:10154:14)
    at Object.rollup (/home/sboyls/node_modules/chartjs-plugin-streaming/node_modules/rollup/dist/rollup.js:10225:3)
    at /home/sboyls/node_modules/chartjs-plugin-streaming/node_modules/rollup-stream/index.js:65:19
    at process._tickCallback (internal/process/next_tick.js:109:7)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:502:3

Help!

Spacing between X-axis ticks

My chart data refreshes every 3 seconds. I've set the X-axis stepSize to 20 so I have a 20-second interval between ticks. But the resulting chart shows big gaps between these ticks. Is there a way to "squeeze" them so the intervals are close to each other?

JSFiddle: https://jsfiddle.net/xbqthaoL/5/

til option is not available

It looks like the ttl option is not available in npm yet. Will you be able to release it pretty soon?

Thank you!

Intergate streaming plugin with annotation plugin.

Hi, your plugin is very neat and useful. Thanks for the effort!
As I'm trying to create a real time data control chart. I'm using your plugin for streaming data and annotation plugin to draw UCL & LCL (Upper Control Limit & Lower Control Limit) lines. The problem is that when the chart is moved to the left, the annotation lines, which must be static, are moved as well. Screenshot attached below.
Annotations are moved
Is it possible to make the annotation lines static just like the axises? Thanks in advance!

Multiple Y-axis

Is there a feature for multiple Y-axis data? I want to plot my live points similar to the attached mock.

trend mock

Error occurs in Angular when after updating to v1.6.0

core.js:1598 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'removeEventListener' of null
TypeError: Cannot read property 'removeEventListener' of null
    at Object.destroy (chartjs-plugin-streaming.js:874)
    at Object.notify (core.plugins.js:109)
    at Chart.destroy (core.controller.js:767)
    at BaseChartDirective.push../node_modules/ng2-charts/charts/charts.js.BaseChartDirective.ngOnDestroy (charts.js:51)
    at callProviderLifecycles (core.js:10420)
    at callElementProvidersLifecycles (core.js:10388)
    at callLifecycleHooksChildrenFirst (core.js:10378)
    at destroyView (core.js:11442)
    at callViewAction (core.js:11568)
    at execComponentViewsAction (core.js:11490)
    at Object.destroy (chartjs-plugin-streaming.js:874)
    at Object.notify (core.plugins.js:109)
    at Chart.destroy (core.controller.js:767)
    at BaseChartDirective.push../node_modules/ng2-charts/charts/charts.js.BaseChartDirective.ngOnDestroy (charts.js:51)
    at callProviderLifecycles (core.js:10420)
    at callElementProvidersLifecycles (core.js:10388)
    at callLifecycleHooksChildrenFirst (core.js:10378)
    at destroyView (core.js:11442)
    at callViewAction (core.js:11568)
    at execComponentViewsAction (core.js:11490)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4053)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
    at invokeTask (zone.js:1540)

It works fine in the chart view. The error occurs when I leave the chart view.

Any way to obtain the Chart object without importing Chart.js?

Here is my code:

import { Component, OnInit } from '@angular/core';
import 'chartjs-plugin-streaming';
import { ActivatedRoute } from '../../../node_modules/@angular/router';

@Component({
  selector: 'app-resource-monitor',
  templateUrl: './resource-monitor.component.html',
  styleUrls: ['./resource-monitor.component.css']
})
export class ResourceMonitorComponent implements OnInit {

  datasets: any[] = [{
    data: [],
    label: 'line1'
  }, {
    data: [],
    label: 'line2'
  }];
  options: any = {
    scales: {
      xAxes: [{
        type: 'realtime'
      }]
    },
    plugins: {
      streaming: {
        onRefresh: function (chart: any) {
          chart.data.datasets.forEach(function (dataset: any) {
            dataset.data.push({
              x: Date.now(),
              y: Math.random()
            });
          });
        },
        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
        frameRate: 30,      // chart is drawn 30 times every second
        pause: false,       // chart is not paused
      }
    },
    animation: {
      duration: 0                    // general animation time
    },
    hover: {
      animationDuration: 0           // duration of animations when hovering an item
    },
  };

  constructor(private route: ActivatedRoute) { }

  ngOnInit(): void {
    this.route.params.subscribe(params => {
      const id = params['id'];
    });
  }

  pause() {
    this.options.plugins.streaming.pause = !this.options.plugins.streaming.pause;
  }
}

I want to start/pause the chart.
It seems like I need to update the chart after setting this.options.plugins.streaming.pause as true.
So I wonder if there is any way to obtain the chart object and call chart.update().

Thanks a lot!!!

[Angular]How do I control the refresh timing with input binding other than with the numeric value

@Input() a

...

this.chartObj = new Chart(this.el.nativeElement.getContext('2d'), {
	...
	options: {
		plugins: {
			streaming: {
				refresh: 1000, // onRefresh callback will be called every 1s
				onRefresh: (chart: Chart) => {
					// something
				}
			}
		}
	}
});

With the above snippet, I'd like to control the refresh the chart when I get the new input data a but apparently, the datasets only get updated every 1s.

I've tried using ngOnChanges cycle, pushing the new data to the datasets and update the chart instance but it didn't seem to work.

this.chartObj.config.data.datasets.push({
  // label: 'Dataset ' + config.data.datasets.length,
  // backgroundColor: color(newColor).alpha(0.5).rgbString(),
  // borderColor: newColor,
  fill: false,
  lineTension: 0,
  data
});
this.chartObj.update();

What am I missing?

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.