mym*_*and 1 javascript jquery flot
我尝试使用Flot char中的以下代码绘制图表.图表是按预期绘制的,但不是工具提示
$(function() {
var data = [["Aug 06",2],["Aug 07",1],["Aug 08",1.5],["Aug 09",0],["Aug 10",0],["Aug 11",0],["Aug 12",0]];
var options = {
series: {
lines: { show: true,
lineWidth: 1,
fill: true, fillColor: { colors: [ { opacity: 0.5 }, { opacity: 0.2 } ] }
},
points: { show: true,
lineWidth: 2
},
shadowSize: 0
},
grid: { hoverable: true,
clickable: true,
tickColor: "#eeeeee",
borderWidth: 0,
hoverable : true,
clickable : true
},
tooltip : true,
tooltipOpts : {
content : "Your sales for <b>%x</b> was <span>$%y</span>",
defaultTheme : false
},
xaxis: {
mode: "categories",
tickLength: 0
},
yaxis: {
min: 0
} ,
selection: {
mode: "x"
}
};
$.plot("#section-chart", [ data ], options);
// Add the Flot version string to the footer
$("#footer").prepend("Flot " + $.plot.version + " – ");
});
Run Code Online (Sandbox Code Playgroud)
当悬停值时,工具提示显示"您的%x的销售额为2美元"而不是它应该显示 Your sales for Aug 06 was $2
如何将x轴值作为工具提示传递给flot图表?我在这方面做错了什么.好心劝告 ?
解决问题的最简单方法是content
用回调替换字符串:
tooltipOpts : {
content : getTooltip,
defaultTheme : false
},
Run Code Online (Sandbox Code Playgroud)
我定义getTooltip
了获得你想要的输出:
function getTooltip(label, x, y) {
return "Your sales for " + x + " was $" + y;
}
Run Code Online (Sandbox Code Playgroud)
正如您在更新后的jsFiddle中所看到的那样,它可以正常工作,但您可能需要在评论中考虑船长的建议,并了解您的情况最佳.
归档时间: |
|
查看次数: |
12424 次 |
最近记录: |