【问题标题】:How to set highchart legend style?如何设置highchart图例样式?
【发布时间】:2023-03-17 19:43:02
【问题描述】:

我做了一个 jsfiddle 示例来演示这个。
http://jsfiddle.net/daxu/ttxvpduv/

    $(function () {
    $('#container').highcharts({

        legend: {
            enabled: true
        },

        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },

        series: [{
            name:'a',
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        },
                {
            name:'b',
                    type:'area',
            data: [129.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]
    });
}); 

在我的示例中,我有两个系列(一行,一个区域)。我们可以看到折线图的图例是一条线,图例区域更大(像一个区域)。

有没有办法让所有图例变成一条线或某种样式?

非常感谢

【问题讨论】:

  • 你需要像主题stackoverflow.com/questions/27510810/…一样使用“假”系列
  • 看到了那个例子,但是我怎样才能让假系列显示在底部而不是右边呢?我们所有的传说都需要在底部。

标签: highcharts


【解决方案1】:

这有点 hacky(也许我最近使用 d3.js 太多了)但您可以即时修改 SVG:

, function(chart){
    // remove the line and rect
    $('.highcharts-legend-item path, .highcharts-legend-item rect').remove();
    // add in your own elements
    $('.highcharts-legend-item').each(function(i, obj){
        var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
        $(circle).attr({"r":10,"fill":"red", "cy": 10});
        $(obj).append(circle);
    });
});

小提琴here.

【讨论】:

    【解决方案2】:

    现在解决了。

    http://jsfiddle.net/ttxvpduv/2/

       Highcharts.seriesTypes.line.prototype.drawLegendSymbol = 
         Highcharts.seriesTypes.column.prototype.drawLegendSymbol;
    

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多