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.

Cannot get annotation plugin to work.

See original GitHub issue

I am trying to get the chartjs-plugin-annotation working in my test project here

Here is my Barchart.vue file, which is how I understand the plugin should be registered

<script>
import { Bar, mixins } from "vue-chartjs";
import chartJsPluginAnnotation from "chartjs-plugin-annotation";
const { reactiveProp } = mixins;

export default {
  extends: Bar,
  mixins: [reactiveProp],
  props: ["chartData", "options"],
  mounted() {
    this.addPlugin(chartJsPluginAnnotation);
    this.renderChart(this.chartData, this.options);
  },
};
</script>

This is the template for the parent component:

<template>
  <div class="small">
    <button @click="fillData()">Randomize</button>
    <bar-chart
      v-if="loaded"
      :chart-data="chartData"
      :options="chartOptions"
    />
  </div>
</template>

And this options from the data() section of the same component

data () {
    return {
      chartOptions: {
        responsive: true,
        tooltips: {
          mode: 'index',
          intersect: true
        },
        scales: {
          xAxes: [{
            id: 'time-axis',
            type: 'time',
            stacked: true,
            offset: true,
            time: {
              unit: 'week',
              tooltipFormat: 'll',
              unitStepSize: 1
            },
            scaleLabel: {
              display: true,
              labelString: 'Date'
            }
          }],
          yAxes: [{
            stacked: true
          }]
        },
        annotation: {
          drawTime: 'afterDatasetsDraw',
          annotations: [{
            id: 'vline',
            type: 'line',
            mode: 'vertical',
            scaleID: 'x-axis-0',
            value: '2020-09-05',
            borderColor: 'black',
            borderWidth: 5,
            label: {
              backgroundColor: 'red',
              content: 'Test Label',
              enabled: true
            }
          }]
        }
      },
      chartData: null
    }
  },

The data renders correctly and redraws on the “randomize” button as I need it to, however the annotation is not drawn.

Ideally I need the annotations to be re-rendered when the data is randomized, hence the “setAnnotation” commented out on line 115, but at the moment I’m not getting a static line at all.

Environment

  • vue.js version: 2.6.11
  • vue-chart.js version: 3.5.1
  • chart.js version: 2.9.4
  • npm version: 6.14.8

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
dankellcommented, Jan 18, 2021

Will do. Also trying to see whether I can identify what changed to cause the break.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't get event from chartjs-annotation-plugin on mouseenter
It seems to be a bug in the annotation plugin because if you build the current master and use that as a source...
Read more >
Can't get annotated plugin discovery to fire - Drupal Answers
To debug a plugin manager use it as a service and get the discovered plugins: $type = \Drupal::service('plugin.manager.archiver'); ...
Read more >
1. How to install the Annotation Plugin chartjs ... - YouTube
How to install the Annotation Plugin chartjs- plugin - annotation in Chart.jsIn this video we will explore how to install the annotation plugin...
Read more >
Migrate to v10 | Maps SDK | Android
Inside the DSL block, use code completion in Android Studio to find all available ... In v9, view annotations were included in the...
Read more >
chartjs-plugin-annotation
Annotations for Chart.js. Latest version: 2.1.0, last published: a month ago. Start using chartjs-plugin-annotation in your project by ...
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