如何更改饼图高图中的字体属性?

时间:2013-05-02 23:21:46

标签: javascript jquery css css3 highcharts

我正在使用pie Highchart.js插件,我正在尝试更改包含percentajes类型的标签的某些字体属性。

我试过这个但不起作用...... http://tinker.io/3fc64/6

JS

$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            style: {
                fontFamily: 'Lato',
                color: "red"
            }
        },
        plotOptions: {
            pie: {
                cursor: 'pointer'
            }
        },
        credits: false,
        title: false,
        tooltip: false,
        series: [{
            type: 'pie',

            data: [
                {
                    name: 'Example1',
                    y: 40,
                    sliced: true,
                    color: "rgb(10,200,23)"
                },
                ['Example2',   12.0],
                ['Example3',       26.8],
                ['Example4',    8.5],
                ['Example5',     6.2],
                ['Example6',   0.7]
            ]
        }]
    });
});

CSS

@import url(http://fonts.googleapis.com/css?family=Lato);

HTML

<div id="container" style="width:100%; height:400px;"></div>

我想念的是什么?有任何想法或建议吗?提前谢谢。

1 个答案:

答案 0 :(得分:21)

您可以通过向dataLabels - &gt;添加plotOptions块来设置Highschart.js生成的内联样式。 pie并定义一些样式属性:

plotOptions: {
    pie: {
        cursor: 'pointer',
        dataLabels: {
            enabled: true,
            color: 'red',
            style: { fontFamily: '\'Lato\', sans-serif', lineHeight: '18px', fontSize: '17px' }
        }
    }
}

这是您更新的tinker

如果您想在style块中控制字体的颜色,则需要使用fill属性。

这是默认情况下设置的属性(您可能希望使用style设置覆盖):

font-family:'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#666;
line-height:14px;
fill:#666;

但如果需要,您可以定义更多。

注意:您还可以通过dataLabels块传递data块来控制各个标签的样式,就像您定义某个饼的样式一样楔子:

{
name: 'Example1',
y: 40,
sliced: true,
color: 'rgb(10,200,23)',
dataLabels: { style:{ /* your style properties here */ }}
}