JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://www.flotcharts.org/flot/jquery.flot.js"></script>
<script src="https://rawgithub.com/krzysu/flot.tooltip/master/js/jquery.flot.tooltip.js"></script>
<div id="flotchart" style="width:300px;height:200px"></div>
JavaScript
$(function() {
var ds = [];
ds.push({
label: 'One',
data : [[1,0]]
});
ds.push({
label: 'Two',
data : [[2,1]]
});
ds.push({
label: 'Three',
data : [[3,2]]
});
var options = {
//colors : colorArray,
grid : {
hoverable : true,
clickable : true
},
series: {
stack:true,
bars: {
show : true,
barWidth : 0.8,
horizontal: true,
align: "center"
}
},
xaxis: {
tickFormatter: function(val, axis) { return val < axis.max ? val : "Cost"; }
},
yaxis: {
//ticks: company_label
},
xaxis:{
max: 4
},
legend: {
show: false,
position: "ne",
noColumns : 1,
backgroundOpacity: 0.5,
//margin: [0, -70]
},
tooltip : true,
tooltipOpts : {
content : "<b>%s</b> : <span>$%x</span>",
defaultTheme : false,
}
};
// Plot the graph with the data and options provided
var somePlot = $.plot($("#flotchart"), ds, options);
var ctx = somePlot.getCanvas().getContext("2d");
var series = somePlot.getData();
var xaxis = somePlot.getXAxes()[0];
var yaxis = somePlot.getYAxes()[0];
var offset = somePlot.getPlotOffset();
ctx.font = "16px 'Segoe UI'";
ctx.fillStyle = "black";
for (var i = 0; i < series.length; i++){
var text = '$' + series[i].data[0][0];
var metrics = ctx.measureText(text);
var xPos = (xaxis.p2c(series[i].data[0][0])+offset.left);
var yPos = yaxis.p2c(series[i].data[0][1]) + offset.top + 5;
ctx.fillText(text, xPos, yPos);
}
});