代码之家  ›  专栏  ›  技术社区  ›  Marcus Christiansen

highchart.js自定义Y轴断续器

  •  1
  • Marcus Christiansen  · 技术社区  · 6 年前

    我已经设置了一个highchart.js象限,如下所示。

    enter image description here

    我正在努力找出如何将顶部Y轴值设置为100而不是140。我已经将断续器设置为70,因为我要求Y轴显示一个断续器为70,最大值为100。每个盒子的高度也应该反映这一点,这样盒子的最下面一行比最上面一行高。

    我的代码如下:

    var qx = $('#quadrant-x').attr('data-match');
                var qy = $('#quadrant-y').attr('data-match');
    
                // Highchart Data
                var data = [
                    { x:parseInt(qx), y:parseInt(qy) }
                ];
    
                var chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'quadrant',
                        defaultSeriesType:'scatter',
                        borderWidth:1,
                        borderColor:'#ccc',
                        marginLeft:90,
                        marginRight:50,
                        backgroundColor:'#eee',
                        plotBackgroundColor:'#fff',
                    },
                    credits:{enabled:false},
                    title:{
                        text:''
                    },
                    legend:{
                        enabled:false                                
                    },
                    // tooltip: {
                    //     formatter: function() {
                    //         return '<b>'+ this.series.name +'</b><br/>'+
                    //             this.x +': '+ this.y;
                    //     }
                    // },
                    plotOptions: {
                        series: {
                            shadow:false,
                        }
                    },
                    xAxis:{
                        title:{
                            text:'Persistence'
                        },
                        min:0,
                        max:100,
                        tickInterval:50,
                        tickLength:0,
                        minorTickLength:0,
                        gridLineWidth:1,
                        showLastLabel:true,
                        showFirstLabel:false,
                        lineColor:'#ccc',
                        lineWidth:1                
                    },
                    yAxis:{
                        title:{
                            text:'Passion',
                            rotation:270,
                            margin:25,
                        },
                        min:0,
                        max:100,
                        tickInterval:70,
                        tickLength:3,
                        minorTickLength:0,
                        lineColor:'#ccc',
                        lineWidth:1        
                    },
                    series: [{
                        color:'white',
                        data: data
                    }]
                }, function(chart) { // on complete
    
                    var width = chart.plotBox.width / 2.0;
                    var height = chart.plotBox.height / 2.0 + 1;
    
                    // console.log(chart);
                    // console.log(chart.plotBox.x);
                    // console.log(width);
                    // console.log(chart.plotBox.y);
                    // console.log(height);
    
                    chart.renderer.rect(chart.plotBox.x, chart.plotBox.y, width, height, 1)
                        .attr({
                            fill: '#3948cf',
                            zIndex: 0
                        })
                        .add();
    
                    chart.renderer.rect(chart.plotBox.x + width, chart.plotBox.y, width, height, 1)
                        .attr({
                            fill: '#00be1d',
                            zIndex: 0
                        })
                        .add();
    
                    chart.renderer.rect(chart.plotBox.x, chart.plotBox.y + height, width, height, 1)
                        .attr({
                            fill: '#ff0000',
                            zIndex: 0
                        })
                        .add();
    
                    chart.renderer.rect(chart.plotBox.x + width, chart.plotBox.y + height, width, height, 1)
                        .attr({
                            fill: '#ff4e00',
                            zIndex: 0
                        })
                        .add();
                });
    

    我尝试在rect()函数中设置不同的值,但这只会更改彩色覆盖。

    有没有我不见的选择?

    1 回复  |  直到 6 年前
        1
  •  1
  •   ewolden    6 年前

    您可以使用 tickPositions . 这个 yAxis 那会是

    yAxis: {
      tickPositions: [0, 70, 100],
      ...
    }
    

    工作坐标: https://jsfiddle.net/v4s3gsm9/1/ (覆盖由asker更新)