question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotation plugin gets disabled on adding streaming plugin ( react )

See original GitHub issue

Expected behavior

Both the plugins should work seamlessly

Current behavior

I have 2 plugins in my chart.js project

  • The annotation plugin
  • The streaming plugin

The annotation plugin works fine until I register the Streaming plugin together.

Now only the streaming plugin works.

Reproducible sample

https://stackblitz.com/edit/chartjs-reproduced-error?file=components/LineChart.js

Optional extra steps/info to reproduce

Code snippet -

import { Line } from "react-chartjs-2";

import Chart from "chart.js/auto";
import annotationPlugin from "chartjs-plugin-annotation";

import "chartjs-adapter-luxon";
import ChartStreaming from "chartjs-plugin-streaming";

Registering the plugins

  Chart.register(annotationPlugin);
  Chart.register(ChartStreaming);

// some stuff here

return <Line data={data} plugins={annotationPlugin} options={options} />

Versions of the packages -

        "chart.js": "^3.7.0",
        "chartjs-adapter-luxon": "^1.1.0",
        "chartjs-plugin-annotation": "^1.3.1",
        "chartjs-plugin-streaming": "^2.0.0",
        "next": "12.0.10",
        "react": "17.0.2",
        "react-chartjs-2": "^4.0.1",

Annotation Config -

   plugins: {
            autocolors: false,
            annotation: {
              annotations: {
                line1: {
                  drawTime: "afterDatasetsDraw",
                  yScaleID: "yAxes",
                  type: "line",
                  yMin: 43170,
                  yMax: 43170,
                  borderColor: function (context) {
                    const chart = context.chart;
                    const { ctx, chartArea } = chart;

                    if (!chartArea) {
                      // This case happens on initial chart load
                      return;
                    }
                    return getGradient(ctx, chartArea, 30000);
                  },
                  borderWidth: 2,
                },
              },
            }

Streaming config -

 xAxes: {
              beginAtZero: false,
              ticks: {
                color: "#45EED0",
                maxTicksLimit: 10,
              },
              grid: {
                display: false,
                borderColor: "#2B2D65",
              },
              type: "realtime",
              realtime: {
                duration: 20000,
                refresh: 1000,
                delay: 2000,
                onRefresh: onRefresh,
              },
            }

Possible solution

No response

Context

No response

chart.js version

“chart.js”: “^3.7.0”,

Browser name and version

Chrome 98.0.4758.82

Link to your project

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
LeeLenaleeecommented, Feb 19, 2022

Error seemed to be that you renamed your X axis ID and the annotation plugin expected x as an ID while you named it xAxes: https://stackblitz.com/edit/chartjs-reproduced-error-5ayyah?file=components%2FLineChart.js

0reactions
GeoBrodascommented, Feb 19, 2022

Thankyou very much @LeeLenaleee , sorry for the trouble. But God bless you! It’s working!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Streaming Real-time data with react and chartjs-plugin ...
1 Answer 1 · It says "Attempted import error: 'RealtimeScale' is not exported from 'chartjs-plugin-streaming' " · Are you using version 2 (latest) ......
Read more >
Add support for annotations | Grafana documentation
This guide explains how to add support for annotations to an existing data source plugin. This guide assumes that you're already familiar with...
Read more >
react-annotation-tool-updated - npm package - Snyk
Props ; hasReview, Enable review after users click submit button, Boolean ; numAnnotationsToBeAdded, Number of annotations users can be added, Number ; onSubmit ......
Read more >
How To Debug React Components Using React Developer ...
Visit the Chrome plugin page for React Developer Tools to install the extension. Click on the Add to Chrome button. Then click on...
Read more >
Plugin Development - Gerrit Code Review
The Gerrit server functionality can be extended by installing plugins. ... The plugin name will get appended to the annotated name, with an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found