我正在使用浮动图表。我有多个 y 轴。如何使所有y轴加粗?
$(function () {
function generate(start, end, fn) {
var res = [];
for (var i = 0; i <= 100; ++i) {
var x = start + i / 100 * (end - start);
res.push([x, fn(x)]);
}
return res;
}
var data = [
{ data: generate(0, 10, function (x) { return Math.sqrt(x)}), xaxis: 1, yaxis:1 },
{ data: generate(0, 10, function (x) { return Math.sin(x)}), xaxis: 1, yaxis:2 },
{ data: generate(0, 10, function (x) { return Math.cos(x)}), xaxis: 1, yaxis:3 },
{ data: generate(0, 10, function (x) { return Math.tan(x)}), xaxis: 1, yaxis: 4 }
];
var plot = $.plot($("#placeholder"),
data,
{
xaxis: [
{ position: 'bottom' },
],
yaxes: [
{ position: 'left', labelWidth : 18},
{ position: 'right', tickColor:'black', labelWidth : 18, tickDecimals: 0},
{ position: 'right' , tickColor:'black', labelWidth : 18, tickDecimals: 0},
{ position: 'right', tickColor:'black', labelWidth : 18}
],
grid: {
clickable: true,
borderWidth: 0,
hoverable: true,
aboveData: true,
markings: [ { yaxis: { from: 0, to: 0 }, color: "#000" },
{ xaxis: { from: 0, to: 0 }, color: 'black' }, { xaxis: { from: 0, to: -1 }, color: "green" }]
},
zoom: {
interactive: true
},
});
function getBoundingBoxForAxis(plot, axis) {
var left = axis.box.left, top = axis.box.top,
right = left + axis.box.width, bottom = top + axis.box.height;
// some ticks may stick out, enlarge the box to encompass all ticks
var cls = axis.direction + axis.n + 'Axis';
plot.getPlaceholder().find('.' + cls + ' .tickLabel').each(function () {
var pos = $(this).position();
left = Math.min(pos.left, left);
top = Math.min(pos.top, top);
right = Math.max(Math.round(pos.left) + $(this).outerWidth(), right);
bottom = Math.max(Math.round(pos.top) + $(this).outerHeight(), bottom);
});
return { left: left, top: top, width: right - left, height: bottom - top };
}