javascript - 在 highcharts 中移动 x 轴(刻度、标签和线)

标签 javascript jquery highcharts

是否可以在 highcharts 中移动 x 轴的 y 位置?到目前为止,我只能使用

将其移动到图表的顶部或底部
opposite: true/false

但现在我需要它位于图表的中间,具有固定的 y 值。我当前的代码是

$(function () {
var chart;
$(document).ready(function () {
    chart = new Highcharts.Chart({
        chart: {
            type: 'spline',
            renderTo: 'container'
        },
        title: {
            text: 'Title'
        },
        xAxis: {
            opposite: true,
            min: 0,
            max: 4,
            reversed: true,
            startOnTick: true,
            endOnTick: true,
            lineWidth: 1
        },
        yAxis: {
            labels: {
                enabled: true
            },
            title: null,
            gridLineWidth: 0,
            min: 1,
            max: 3.1
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        credits: {
            enabled: false
        },
        series: [{
            marker: {
                enabled: false
            },
            name: 'Year 1800',
            data: [
                [1, 1],
                [2.5, 1]
            ],
            showInLegend: false
        }, {
            marker: {
                enabled: false
            },
            name: 'Year 1900',
            data: [
                [1.5, 2],
                [3, 2]
            ],
            showInLegend: false
        }, {
            name: 'name1',
            data: [
                [2, 3]
            ],
            type: 'scatter',
            zindex: 10
        }, {
            name: 'name2',
            data: [
                [3, 3]
            ],
            type: 'scatter'
        }, {
            name: 'name3',
            data: [
                [1.5, 3]
            ],
            type: 'scatter'
        }]
    });
});
});

我的 JSfiddle 是 http://jsfiddle.net/5xum/fVpqU/7/ .

我希望 x 轴(连同刻度和标签)在两个不同数据集之间穿过 y=2.5。 HighCharts 支持吗?

最佳答案

您可以使用 offset 属性来移动 xAxis。在您的情况下,您必须使用负偏移量将 xAxis 向下移动:

    xAxis: {
                opposite: true,
                min: 0,
                max: 4,
                reversed: true,
                startOnTick: true,
                endOnTick: true,
                lineWidth: 1,
                offset: -130
            },

关于javascript - 在 highcharts 中移动 x 轴(刻度、标签和线),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20330284/

相关文章:

javascript Today() 函数

jquery - Page_ClientValidate 未定义 (ASP.NET MVC)

javascript - Jquery + GSAP 从 onComplete 函数访问本地计算的值

javascript - 由于额外的 $$hashKey,angularjs 函数失败

javascript - 如何更改多个数组对象的索引?

javascript - 从 Angular 中的 BehaviorSubject 访问嵌套数据

highcharts - 动态添加系列 Highcharts

javascript - 传单中的标记悬停

javascript - Highcharts 实心标尺宽度?

javascript - 未捕获的语法错误 : Unexpected token ILLEGAL in javascript