海图 : labels inside columnrange bar

标签 highcharts range labels

我正在使用 Highcharts-more 中的 columnrange 类型。
默认数据标签格式化程序将最小/最大数据放在范围的两端,这很好。

有没有办法在每个点上附加另一个标签? (例如:数据名称,就在栏的中间)

请在以下位置查看我的工作:
JSFiddle

这是一个有生命范围的家谱。
我想在条形中心显示工具提示中显示的名称。

(仅供引用,我尝试使用渲染器用文本重载图表:它有效......但文本附加到图表,而不是点,缩放将它们留在原地,而点移动。是否有可能将文本标签附加到图表 onLoad 事件上的每个点的方法?)

谢谢你。

$(function () {

$('#container').highcharts({

    chart: {
        type: 'columnrange',
        inverted: true,
        marginLeft: 40,
        zoomType: 'xy'
    },

    title: {
        text: 'My family tree'
    },

    xAxis: {

        labels: {
            enabled: false
        },
        min: 0,
        max: 10
    },

    yAxis: {
        type: 'datetime',
        min: new Date().setYear(1900).valueOf(),
        max: new Date().valueOf(),
        title: {
            text: 'Year'
        },
        endOnTick: false
    },

    legend: {
        enabled: false
    },

    plotOptions: {
        columnrange: {
            grouping: false,
            pointPadding: 0,
            dataLabels: {
                enabled: true,
                useHTML: true,
                formatter: function () {
                    if (new Date().setHours(0, 0, 0, 0) !== new Date(this.y).setHours(0, 0, 0, 0)) return '<span style="color:black">' + Highcharts.dateFormat('%Y', this.y) + '</span>';
                    else return '';
                }
            }
        }
    },

    tooltip: {
        headerFormat: '{series.name}<br/>',
        formatter: function () {
            var l = this.point.name + '<br/>' + Highcharts.dateFormat('%e/%m/%Y', this.point.low);
            if (new Date().setHours(0, 0, 0, 0) !== new Date(this.point.high).setHours(0, 0, 0, 0)) l += '<br/>' + Highcharts.dateFormat('%e/%m/%Y', this.point.high);
            return l;
        }
    },

    series: [{
        color: 'rgb(100,100,255)',
        pointWidth: 150,
        data: [{
            name: 'Yann B',
            low: Date.UTC(1976, 1, 27),
            high: new Date().valueOf(),
            x: 1 * 10 / 2
        }]
    }, {
        color: 'rgb(150,150,255)',
        pointWidth: 70,
        data: [{
            name: 'Jean-Yves B',
            low: Date.UTC(1947, 3, 26),
            high: Date.UTC(2006, 2, 10),
            x: 1 * 10 / 4
        }, {
            name: 'Josiane M',
            low: Date.UTC(1946, 8, 21),
            high: Date.UTC(1998, 11, 26),
            x: 3 * 10 / 4
        }]
    }, {
        color: 'rgb(200,200,255)',
        pointWidth: 30,
        data: [{
            name: 'Guillaume B',
            low: Date.UTC(1907, 7, 4),
            high: Date.UTC(1988, 1, 11),
            x: 1 * 10 / 8
        }, {
            name: 'Marie-Jeanne S',
            low: Date.UTC(1911, 7, 17),
            high: Date.UTC(1986, 2, 3),
            x: 3 * 10 / 8
        }, {
            name: 'Joseph M',
            low: Date.UTC(1921, 3, 11),
            high: Date.UTC(1996, 4, 23),
            x: 5 * 10 / 8
        }, {
            name: 'Marie K',
            low: Date.UTC(1925, 4, 4),
            high: new Date().valueOf(),
            x: 7 * 10 / 8
        }]
    }]

});

});

最佳答案

“内部”的使用在这里确实是相关的。但是我不得不绕过其使用固有的错误(请参阅对最后一个答案的评论)。

这是一段适用于数据标签的代码。工具提示仍然存在 zIndex 问题,我将尽快发布更完整的解决方案。
http://jsfiddle.net/SineDie/TREwr/1/

dataLabels: {
        inside: true,
        enabled: true,
        useHTML: true,
        formatter: function () {
             if (this.y === this.point.low) {
                    var l = '<div style="text-align:center;color:black;width:' + (this.point.plotLow - this.point.plotHigh) + 'px">' 
                        + Highcharts.dateFormat('%Y', this.point.low) + ' - '
                        + this.point.name;
                    // to avoid marking as dead if still living... 
                    if (new Date().setHours(0, 0, 0, 0) !== new Date(this.point.high).setHours(0, 0, 0, 0))
                         l += ' - ' + Highcharts.dateFormat('%Y', this.point.high);
                    l += '</div>';
                    return l;
                }
             else return '';
        }
   }

关于海图 : labels inside columnrange bar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17958270/

相关文章:

python-3.x - 如何生成频率为周二至周六(含)的 Pandas 日期范围?

javascript - Objective C - UIWebview - 将 javascript 文本范围转换为 objective c 对象,反之亦然

properties - Neo4j中的Label和Property有什么区别?

r - 如何将表达式(cos(alpha))放入标签中?

highcharts - 如何在highcharts中显示日期时间轴上的所有值?

javascript - 无法设置特定数据的条形图宽度,Highcharts

带有 angular2-highcharts 的 JSON 数据

python - 如何使用非包含范围生成类似示例中的列表? (Python)

Neo4j - 将节点标题设置为 Web 界面中的标签

javascript - 自己的工具提示 Highcharts