我需要能够根据另一个标签数组更改(水平)条形图的标签/刻度 - 这是名称解析器的一部分。
因此,我的初始化代码大致如下:
var ticks = [
["abc", 0],
["def", 1],
["ghi", 2],
["jkl", 3]
];
//loop for each value goes here
var data = {
data: [
[0, 111],
[1, 222],
[2, 333],
[3, 444]
], //... etc
bars: {
horizontal: true,
show: true,
barWidth: 0.8,
align: "center"
}
};
var plot = $.plot($("#graph"), data, {
yaxis: {
ticks: ticks
}
//etc
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://www.flotcharts.org/javascript/jquery.flot.min.js"></script>
<div class="chart" id="graph" style="width:400px;height:300px;"></div>
//New ticks for y-axis
plot.yaxisticks = [["ABC", 0], ["DEF", 1], ["GHI", 2], ["JKL", 3]];
plot.draw();
编辑:
所以我可以通过 plot.getOptions().yaxis.ticks[i][1] = value
设置值,但似乎无法使用 plot.setupGrid()
重新绘制刻度。有助于吗?