1

我正在尝试使用 FlotChart 创建堆积条形图。我的挑战是创建最多 5 层的多个 x 轴标签。所以,我尝试使用 TickRotor 插件(最初是因为我想垂直旋转标签)。

现在,我想在 TickRotor 中画一些线条并调整一些功能。但是,在我的图表中某处绘制了一条奇怪的线。你能帮我看看发生了什么吗?

这是“其他”部分plot.hooks.draw.push(function (plot, ctx)

if (ticks.length == 0) {
    return;
}
xaxis = plot.getAxes().xaxis;
var box = xaxis.box;
var tick, label, xoffset, yoffset;
var showWeek = false;
for (var i = 0; i < ticks.length; i++) {
    tick = ticks[i];
    if (!tick.label) {
        continue;
    }
    ctx.save();
    ctx.font = font;
    if (rotateTicks <= 90) {
        // Center such that the top of the label is at the center of the tick.
        xoffset = -Math.ceil(Math.cos(radsAboveHoriz) * tick.height) - 10;
        yoffset = Math.ceil(Math.sin(radsAboveHoriz) * tick.height) - 10;
        ctx.translate(Math.round(plot.getPlotOffset().left + xaxis.p2c(tick.v)) + xoffset,
                      box.top + box.padding + plot.getOptions().grid.labelMargin + yoffset);
        ctx.rotate(rotateTicksRads);
    } else {
        // We want the text to facing up, so we have to
        // rotate counterclockwise, which means the label
        // has to *end* at the center of the tick.
        xoffset = Math.ceil(Math.cos(radsAboveHoriz) * tick.height)
                  - Math.ceil(Math.cos(radsAboveHoriz) * tick.width);
        yoffset = Math.ceil(Math.sin(radsAboveHoriz) * tick.width)
                  + Math.ceil(Math.sin(radsAboveHoriz) * tick.height);
        ctx.translate(Math.round(plot.getPlotOffset().left + xaxis.p2c(tick.v) + xoffset),
                      box.top + box.padding + plot.getOptions().grid.labelMargin + yoffset);
        ctx.rotate(-radsAboveHoriz);
    }
    var ticksMe = tick.label.split(" ");

    // draw labels
    ctx.fillText(ticksMe[0], 0, 0);
    if(showWeek){
        ctx.fillText(ticksMe[1], xoffset, yoffset * 2);
        showWeek = false;
    }
    else{
        showWeek = true;
        ctx.moveTo(-4,-10);
        ctx.lineTo(-4,(yoffset * 2));
        ctx.stroke();
    }

    ctx.restore();
}

这是显示奇怪线绘制位置的图像: 奇怪的线条是绘制的图像

4

0 回答 0