You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constaddAnnotations=(event,chart,config)=>{chart.clearAnnotations();const{ seriesIndex }=config;const{ xaxis, series }=config.w.config;constoffsetX=getOffsetX(event,seriesIndex,series);constdataPoints=series[seriesIndex].data;constannotations=dataPoints.map(toAnnotation(xaxis.categories,offsetX));annotations.forEach((annotation)=>{chart.addPointAnnotation(annotation,false);});};
At the moment i'm getting the offsetX with a hack:
constgetOffsetX=(event,seriesIndex,series)=>{const{ width }=event.target.getBBox();// get the collumn widthconstseriesWidth=series.length*width;// get the whole series widthconststartOffset=0-seriesWidth/2;// get the start of the offset from midpoint 0 is middlereturnstartOffset+seriesIndex+seriesIndex*width;// calculate the +- offset for the label};
And this is the toAnnotation function just in case you need more information:
consttoAnnotation=(categories,offsetX)=>(point,i)=>{constcategory=categories[i];return{x: category,y: point,label: {
offsetX,text: `${point}%`,// other settings to make the text look as i want},marker: {size: 0,},};};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, i've been reading the docs and can't find a nice way to implement this kind of behaviour:
Question is there a defined way of doing this?
I could not find anything in the documentation about how to create these kinds of labels/annotations
Explanation of current solution
Where i show the annotation on top of every collumn in the series.
What i do now:
I add mouse events
where
addAnnotations
does the following:At the moment i'm getting the offsetX with a hack:
And this is the
toAnnotation
function just in case you need more information:Beta Was this translation helpful? Give feedback.
All reactions