【问题标题】:Highcharts styling, Legend & custom fontsHighcharts 样式、图例和自定义字体
【发布时间】:2012-10-08 08:08:07
【问题描述】:

在将 自定义字体 应用于图例项时,我在设置 Highcharts 中的图例项时遇到问题。实际上项目彼此如此接近,itemMarginBottomitemMarginTop 不起作用。

这是我的Highcharts 代码的一部分:

legend: {
    enabled: true,
    y: 20,
    align: 'right',
    verticalAlign: 'top',
    margin: 30,
    width: 200,
    borderWidth: 0,
    itemMarginTop: 15,
    itemMarginBottom: 15,
    itemStyle: {
            color: '#000',
            fontFamily: 'MuseoS500'
    }
},

这是传说中的截图:

我的丑陋解决方案:

我像下面这样解决了这个问题,但遗憾的是硬编码:

// it is for the text's in the legend, I'll start from 0 and will
// increase by 10, so it's adding 10 pixels extra space to the next one
var z = 0;    

// this is for tiny-lines near the texts in legend, they starts from 14
// and increasing by 14 also ...
var p = 14;

// loop through <text> tags, which are texts in the lgened
$('.highcharts-legend > text').each( function (i) {

    // they have 'x' and 'y' attribute, I need to work on 'y' obviously
    y = parseInt($(this).attr('y'));

    // increasing 'y' value ...
    $(this).attr('y', y + z);

    // next element is <path>, the colorful lines ...
    $(this).next().attr('transform', 'translate(30,' + p + ')');

    // increasing the values, for the next item in the loop ...
    z = z + 10;
    p = p + 10 + 14;

});

我知道这很愚蠢,但我无法以任何其他方式解决这个问题,我不得不让它们以某种方式工作。我也很乐意听到你的想法...... :)

补丁后的新传说:

【问题讨论】:

  • 这可能是一个错误吗?我的意思是它看起来很奇怪...... :(
  • 我可能遗漏了一些东西,但我看不出该屏幕截图有什么问题。
  • @wergeld 上边距和下边距设置为 15,但你看不到那里......我已经用 JS 解决了这个问题,很快就会在这里发布。 :)
  • 是的,在图例图像上显示边框可能会更好,这样可以看到边距的差异。
  • @wergeld 我已经用我自己的解决方案更新了这个问题。问题是图例上的项目之间的距离(如行高),而不是图例框架的边距。顺便说一句,我猜也很清楚没有边界。 :)

标签: css highcharts custom-font


【解决方案1】:

Highchart documentation 表示有一个名为 lineHeight 的属性,但自 Highcharts 2.1 起已弃用

官方Highcharts forum的帖子也证实了这一点。因此,您可以破解源代码以根据需要更改高度,或者尝试在图表渲染后使用 javascript 更正项目高度。

此外,还有一个名为itemStyle 的属性允许为图例项设置 CSS。

例如paddingBottom: '10px'

查看示例:

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/legend/lineheight/

【讨论】:

  • 或者将itemStyle.padding设置为5
  • 感谢 Hardik,如您所见,我已经解决了这个问题,但是您是对的,感谢您提供的信息! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-28
  • 1970-01-01
相关资源
最近更新 更多