css - Highcharts 样式、图例和自定义字体

标签 css highcharts custom-font

自定义字体应用于图例元素时,我在 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'
    }
},

这是图例的屏幕截图:

enter image description here

我丑陋的解决方案:

我解决了这个问题,如下所示,但遗憾的是硬编码:

// 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;

});

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

补丁后的新传奇:

enter image description here

最佳答案

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/

关于css - Highcharts 样式、图例和自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12777635/

相关文章:

javascript - AngularJS:如何 Jasmine 测试指令中的回调函数?

ruby - 在 StockChart 中以编程方式显示多个系列的工具提示(highchart)

javascript - Highcharts 在系列数据中有超过 999 个项目?

android - 我如何在 fragment 布局中使用自定义字体?

html - 如何应用CSS位置:absolute correctly?

css - 单击时图像上出现白色边框 :S

android - 在 Android Studio 中预览自定义字体

html - 如何在 HTML 站点上安装自定义字体

html - CSS: float:left with a margin-right 不会将所有元素推开

javascript - 无法使用 jquery 在 div 中找到事件元素