Comments (5)
@Kiszko - I realise this is quite an old post, but since it's still open, I've been adding text annotations by making a line type annotation, using the label.content property, then setting the line annotation borderColor to transparent. Seems to work for most of what I need. I have a range of data highlighted so it stands out with a box annotation and and a vertical line annotation the same way as above to add a text label for box annotations as well.
Edit: Here's a JSFiddle displaying the concept of the above example - https://jsfiddle.net/WebGaze/875anwz6/
from chartjs-plugin-annotation.
@Kiszko this hasn't been abandoned. I haven't really had time to work on this as most of my time is being spent on updates to Chart.js itself. I'm happy to merge PRs though that add functionality. I'm also happy to add other maintainers if there's someone who wants to do a lot of work on the annotations plugin
from chartjs-plugin-annotation.
@Kiszko - I realise this is quite an old post, but since it's still open, I've been adding text annotations by making a line type annotation, using the label.content property, then setting the line annotation borderColor to transparent. Seems to work for most of what I need. I have a range of data highlighted so it stands out with a box annotation and and a vertical line annotation the same way as above to add a text label for box annotations as well.
Edit: Here's a JSFiddle displaying the concept of the above example - https://jsfiddle.net/WebGaze/875anwz6/
Thanks dude for the awesome example
Guys check the jsfiddle for more details
annotation: {
annotations: [{
type: 'box',
id: 'target-period-1',
xScaleID: 'x-axis-0',
yScaleID: 'y-axis-0',
xMin: 2,
xMax: 7,
yMin: 0,
yMax: 20,
borderColor: 'rgba(255,159,64,1)',
backgroundColor: 'rgba(255,159,64,0.2)',
borderWidth: 1
}, {
type: 'line',
id: 'call-count-1',
mode: 'vertical',
scaleID: 'x-axis-0',
value: 4.5,
borderColor: 'transparent',
label: {
backgroundColor: 'rgba(0,0,0,0.8)',
fontFamily: 'sans-serif',
fontSize: 12,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 12,
yPadding: 6,
cornerRadius: 4,
position: 'center',
yAdjust: -100,
enabled: true,
content: 'Test Label'
}
}],
drawTime: 'afterDraw'
}
from chartjs-plugin-annotation.
Would love to see this added into the plugin as well.
The workaround @hkvongit mentions is sort of workable but has all kinds of issues for many use cases.
I'd add the additional desire for a way to give the text a URL (i.e. a way to make a clickable annotation that's actually a link).
I realize canvas doesn't have links in the traditional sense but it would be possible for the JS to watch for clicks on the annotation and then redirect the user when they click it based on some attribute.
from chartjs-plugin-annotation.
Awesome workaround by @CrescentCraftorium
from chartjs-plugin-annotation.
Related Issues (20)
- Error on documentation: "line" is not a registered controller HOT 2
- Object literal may only specify known properties, and 'annotation' does not exist in specified type HOT 14
- Draw line annotation on top of first dataset but under second dataset HOT 2
- Annotations that are following current Y values should not overlap HOT 10
- Annotation Variations
- Configuring hitRadius for annotations
- Invalid typing probably? HOT 3
- Line annotation when specified with borderWidth:1, the final width of line is 2px HOT 2
- Annotation Collision HOT 1
- Animation curves do not match the axis HOT 1
- Type error in label.d.ts HOT 2
- Setting resizeDelay to non-zero value gives "Cannot read properties of undefined (reading 'left')" on clipArea error HOT 4
- Draggable Annotations don't work in React HOT 3
- Labels of the annotation with Point Type? HOT 1
- annotation in radar charts HOT 3
- Type error with backgroundColor on options parameter for scriptable options HOT 4
- Cannot set properties of undefined (setting 'backgroundColor') HOT 7
- [bug] Updating chart js 4.4.1 introduced some plugin errors with a donut chart. HOT 2
- TypeScript: `xMin`, `xMax`, `yMin`, `yMax` should accept undefined value as Scriptable options return value
- TypeScript: ScaleValue should accept `Date` object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chartjs-plugin-annotation.