gpt4 book ai didi

jquery - 如何在jquery中显示flot图表x轴上的字符

转载 作者:行者123 更新时间:2023-12-01 04:36:54 24 4
gpt4 key购买 nike

我需要在我的项目中使用plot.js 中的更新图表,这是我的代码:

var data = [],
totalPoints = 1200,
$UpdatingChartColors = $("#updating-chart").css('color');

function getRandomData() {
if (data.length > 0)
data = data.slice(1);
while (data.length < totalPoints) {
var prev = data.length > 0 ? data[data.length - 1] : 50;
var y = prev + Math.random() * 10 - 5;
if (y < 0)
y = 0;
if (y > 100)
y = 100;
data.push(y);
}
var res = [];
for (var i = 0; i < data.length; ++i)
res.push([i, data[i]])
return res;
}
var updateInterval = 1500;
$("#updating-chart").val(updateInterval).change(function() {
var v = $(this).val();
if (v && !isNaN(+v)) {
updateInterval = +v;
$(this).val("" + updateInterval);
}
});
var options = {
yaxis: {
min: 0,
max: 100
},
xaxis: {
transform: function(v) {
return -v;
},
min: 0,
max: 90
},
colors: [$UpdatingChartColors],
series: {
lines: {
lineWidth: 1,
fill: true,
fillColor: {
colors: [{
opacity: 0.4
}, {
opacity: 0
}]
},
steps: false
}
}
};

var plot = $.plot($("#updating-chart"), [getRandomData()], options);

我在 x 轴上获得输出,如 90、80、70、60、50、40、30、20、10、0。但我需要 D-90、D-80、D-70、D-60、D-50、D-40、D-30、D-20、D-10 等输出。

如何实现这一目标?

最佳答案

xaxis 选项中使用 tickFormatter 属性:

tickFormatter: function(val, axis) {
return 'D-' + val;
}

参见here一个工作 fiddle 和 here了解更多信息。

PS:使用transform时,您还应该指定inverseTransform

关于jquery - 如何在jquery中显示flot图表x轴上的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50246731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com