Custom HighCharts - change the height of plotLines , show the marker value by default at a specific x and y

ぐ巨炮叔叔 提交于 2019-12-01 15:01:22

1) The plotLines are infinite. The extend as far as the plot area is. So, to limit this, how about you change your yAxis max:

yAxis: {
    max: 8,
    labels: {
        enabled: false
    },
    title: {
        enabled: true,
        text: null
    }
},

Or, you could create a column series on the points you want and give them a certain value for the height you want. Making the columns thin to mimic your plotLines will help like so:

series: [{
            name: '',
            type: 'column',
            pointWidth: 1,
            borderWidth: 0,
            data: [8, 8, 8, 8, 8, 8, 8]
        },
...

2) Which values in the circles (I am guessing)? The "Series 1: XX"? Or the whole tooltip?

EDIT: For question 2 you can do this with a formatter function on the dataLabel for the scatter series (your circles). Here is the function:

var customFormatPoint = function (pointX, seriesIndex) {
    var theChart = $('#container').highcharts();
    var yValue = null;
    var points = theChart.series[seriesIndex].options.data[pointX];
    return points;
};

You call this from:

series: [{
    name: '',
    type: 'column',
    pointWidth: 1,
    borderWidth: 0,
    dataLabels: {
        enabled: true,
        formatter: function () {
            return customFormatPoint(this.point.x, 1);
        }
    },
    data: [7.70, 7.70, 7.70, 7.70, 7.70, 7.70, 7.70]
}, {...

Key element here is that you have this.point.x which is that scatter point's xAxis location. You then need to send in which index the series is that contains the y value you want to show in the dataLabel.

I have also removed the plotLines and created a series that just contains the bars with width of 1 and no border. I had to mess around to get the end of the bar (its max value) to coincide with the scatter circle diameter.

Please see this jsFiddle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!