-
Hi, im trying to draw a horizontal line on my Charts, i get this on console and seems like the plugin is correctly registered. This is my code:
And render the Chart
I already tried with the plugin object inside the options, change y-axis-id ... and several methods i found different websites with no success... Versions i use:
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
Looks like you are trying to use it inline (in config.plugins array) |
Beta Was this translation helpful? Give feedback.
-
@JRA98 maybe I'm wrong but on top of what @kurkle wrote, I see that:
I have tried to update the config you provided: const defaultOptions = (() => {
return {
plugins: {
legend: {
display: false,
position: 'right'
},
annotation: {
annotations: [
{
type: 'line',
scaleID: 'y',
value: 600,
borderColor: 'black',
borderWidth: 10,
label: {
backgroundColor: 'red',
content: 'Test Label',
enabled: true,
},
},
],
},
},
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
gridLines: {
drawOnChartArea: false
},
stacked: true
},
y: {
beginAtZero: true,
gridLines: {
display: true
},
stacked: true
}
},
elements: {
point: {
radius: 0,
hitRadius: 10,
hoverRadius: 4,
hoverBorderWidth: 3
}
},
}
})(); |
Beta Was this translation helpful? Give feedback.
-
It still not showing and break the stacked option... I tried to configure it globally on the index.d.ts of the library node_modules/@coreui/react-chartsjs/src/index.d.ts (maybe its not okay) and still not working
|
Beta Was this translation helpful? Give feedback.
-
@JRA98 can you create a codepen with the complete sample in order to debug it? About registration, having a look to the doc https://www.chartjs.org/chartjs-plugin-annotation/latest/guide/integration.html#bundlers-webpack-rollup-etc import { Chart } from 'chart.js';
import annotationPlugin from 'chartjs-plugin-annotation';
Chart.register(annotationPlugin); and not |
Beta Was this translation helpful? Give feedback.
-
Created a codepen (with shared options): https://codepen.io/stockinail/pen/abyrGav Seems working. |
Beta Was this translation helpful? Give feedback.
-
Not working for me, probably because react-chartsjs... Could i import the plugin inside the @node_module folder on the CChart.js library? Something like this
Im trying something like this, launching npm install to update the changes |
Beta Was this translation helpful? Give feedback.
-
I usually create a file for the chart components I need. // chart-with-plugins.js import Chart from 'chart.js/auto'
import { customTooltips as cuiCustomTooltips } from '@coreui/chartjs'
import '@coreui/chartjs/dist/css/coreui-chartjs.css'
import annotationPlugin from 'chartjs-plugin-annotation';
Chart.register(annotationPlugin);
export default Chart; // chart-component.js import Chart from './chart-with-plugins.js';
... That enables having single point to modify and might also help the bundler to do right things. Note: I messed up with the issue this was created from, and had no other option than to delete it. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Im finally get it works!!
I have directly modified the main node_modules/@coreui/react-chartjs/src/CChart.js library file and extracted it into my libraries folder.
And added the following lines at the start
Then on my Chart Component I read from the …