I have a morris.js bar graph. I want to place count
on top of this graph. I looked into morris.js bar doc, could not find any.
On hover it should display value
but on top of bar it should display count
. Is there a way to do that? something like the given image
Here is my code
Morris.Bar ({
element: 'bar-example',
data: [
{mapname: 's1', value: 10, count: 3},
{mapname: 's2', value: 4, count: 4},
{mapname: 's3', value: 12, count: 13}
],
xkey: 'mapname',
ykeys: ['value'],
labels: ['No. of days'],
barRatio: 0.4,
xLabelAngle: 35,
hideHover: 'auto',
barColors: function (row, series, type) {
console.log("--> "+row.label, series, type);
if(row.label == "s1") return "#AD1D28";
else if(row.label == "s2") return "#DEBB27";
else if(row.label == "s3") return "#fec04c";
}
});
Here is a link where you can test it.
@chiliNUT @abi1964 I placed multiple charts but I am having a problem w/the CSS. The data, bar height etc. all works fine but the #s are being stacked on top. I've tried every iteration of position in the CSS. Ideas or a Fiddle how to fix this?
image of multiple graphs w/#'s stacking
I just found this question whilst looking for the same solution. This is done in javascript / jquery.
I can share with you the code I am using which I discovered by trial, error and research.
The output looks like this.
But what you can try, is change the values here
to something like
This change is untested, but will act as a good starting point.
Regards :)
Here is a start, its a bit hacky, but it gets the job done:
JS
and some CSS to style the divs
CSS
hopefully you can run with that to create the exact effect you are looking for
You can extend Morris to achieve this. Please refer to this answer to see a full working snippet.
Add a property:
Add a prototype to draw the label:
Modify the
Bar.prototype.drawSeries
protoype, adding these lines (before the last else):Then set the
labelTop
property to true in your Morris Bar config:Try by placing this code in CSS
I find better to pass via jQuery to an empty p
This is the final result: Final Result
This is my code:
HTML
JS Below the chart code. Remember to change theData variable to the one you're using in your code.
CSS
I also have added a class to each color.
Hope this helps anybody :) Happy coding!