在amCharts中值为零时显示图形标签

时间:2016-02-01 00:51:34

标签: javascript amcharts

我在amCharts中显示旋转的条形图。我需要显示每个条的标签,无论其值如何。如果值为零,则不显示条形,因此不显示标签。有没有办法可以随时显示标签,无论价值如何?

或者更好的是,有没有办法让graph.labelOffset引用一个函数,该函数将根据值返回不同的数量?

这是我正在使用的Fiddle。请注意,第3项的值为0,因此不显示任何标签。

这是图表的javascript代码。

var gamingData = [
{
    "label": "1",
    "name": "Thinone",
    "grade": 30,
    "pounds": 3.6,
    "percentage": 2.3
},
{
    "label": "2",
    "name": "Studmuffin",
    "grade": 60,
    "pounds": 3.6,
    "percentage": 2.3
},
{
    "label": "3",
    "name": "Slacker",
    "grade": 0,
    "pounds": 3.6,
    "percentage": 2.3
},
{
    "label": "4",
    "name": "Momof2",
    "grade": 60,
    "pounds": 3.6,
    "percentage": 2.3
},
{
    "label": "5",
    "name": "TheVas",
    "grade": 120,
    "pounds": 3.6,
    "percentage": 2.3
}];

var displayGamingChart = function(gamingData, chartDiv) {
var chart = AmCharts.makeChart(chartDiv, {
    "theme": "light",
    "type": "serial",
    "dataProvider": gamingData,
    "graphs": [{
        "balloonText": "Down [[pounds]]lbs and [[percentage]]%",
        "fillAlphas": 1,
        "lineAlpha": 0.2,
        // "title": "Minutes",
        "type": "column",
        "valueField": "grade",
        "labelText": "[[name]]",
        "labelOffset": -75,
        "legendValueText": "",
        "fillColors": "#94BA65"
    }],
    "startDuration": 1,
    "depth3D": 20,
    "angle": 30,
    "rotate": true,
    "categoryField": "label",
    "categoryAxis": {
        "gridPosition": "start",
        "fillAlpha": 0.05,
        "position": "left"
    },
    "export": {
        "enabled": true
     }
});
} 
displayGamingChart(gamingData, "gamingChart");

1 个答案:

答案 0 :(得分:1)

要强制显示标签,即使是那些不适合的标签,请在图表的配置中将showAllValueLabels设置为true

"graphs": [{
    "balloonText": "Down [[pounds]]lbs and [[percentage]]%",
    "fillAlphas": 1,
    "lineAlpha": 0.2,
    // "title": "Minutes",
    "type": "column",
    "valueField": "grade",
    "labelText": "[[name]]",
    "labelOffset": -75,
    "legendValueText": "",
    "fillColors": "#94BA65",
    "showAllValueLabels": true
}]

至于问题的第二部分,没有任何功能可以区分每个条形码的标签偏移量。