javascript - jQuery float 条形数字 : Numbers positioning

标签 javascript jquery charts flot bar-chart

我正在使用jquery.flot.barnumbers.js Javascript plotting (charts) library for jQuery 的插件在栏上显示数字。

我的代码:

$.plot("#placeholderByDay", [
            {
                data: DataOne, label: "Total Calls", bars: {
                    numbers:{
                        show:true,
                        xAlign: 80,//align top
                        yAlign: 1 
                        //yAlign: function(y) { return y+ 1; } //upside of bars
                    }
            } ]);

我现在得到的是:

enter image description here

我需要的是:

enter image description here

因此,当条形图没有数据时,零点应位于轴的正上方,而有值的地方应按原样旋转 90 度。我怎样才能实现这个目标?

最佳答案

哎呀,我did it again .

如果您想放弃该插件并以有趣的方式执行此操作;自己编码。它让您可以自由地以您喜欢的方式进行自定义。

// after you draw the plot
var ctx = somePlot.getCanvas().getContext("2d");
var data = somePlot.getData()[0].data;
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 < data.length; i++){       
    var text = data[i][4] + '';
    var metrics = ctx.measureText(text);
    var xPos = xaxis.p2c(data[i][0]) + offset.left;
    var yPos = yaxis.p2c(data[i][5]) + offset.top + metrics.width + 5;
    // perform the rotation
    ctx.save();
    ctx.translate(xPos, yPos);
    ctx.rotate(-Math.PI/2);
    ctx.fillText(text, 1, 1);
    ctx.restore();
}

示例 here .

关于javascript - jQuery float 条形数字 : Numbers positioning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27353941/

相关文章:

javascript - Chrome 扩展程序的 chrome.tabs.onCreated 和 executescript 不起作用

python - 不断增长的 matplotlib 条形图

ruby-on-rails - rails 。如何将值从数组传递到 google 图表脚本。

javascript - 在 Vue + .Net 核心应用程序中对组件使用导入时,获取 "TypeError: "_Ctor"is read-only"

javascript - 用图像替换文本

javascript - 单击 jquery 对话框中的按钮时出错

javascript - ES6 遍历类方法

javascript - jQuery:动画小数

javascript - DataTable 在编辑后不记得分页页面

primefaces - 不为 Primefaces 5.0 呈现的折线图