0

我正在使用 canvasjs 创建一个圆环图 - 图表本身效果很好,但我希望将标签从图表本身中删除,并且只显示在工具提示中。

我根据我在 canvasjs 网站上阅读的内容尝试了以下内容,但它没有隐藏标签:

    <div id="chartContainer" style="width:150px; height:150px;"></div>

    var chart = new CanvasJS.Chart("chartContainer",
    {
        animationEnabled: true,
        theme: "theme2",
        creditText:"",
        axisY:{
            valueFormatString: " ",
            tickLength: 0
        },
        axisX:{
            valueFormatString: " ",
            tickLength: 0
        },            
        data: [
            {        
                type: "doughnut",
                startAngle:270 ,
                toolTipContent: "{label}: {y}",
                dataPoints: [
                    {  y: 2, label: "L1"},
                    {  y: 3, label: "L2"},
                    {  y: 8, label: "L3"}

                ]
            }
        ]
    });

    chart.render();

有没有办法停止图表本身中显示的标签,但仍有标签值可用于工具提示?

https://jsfiddle.net/befmrhz4/

4

1 回答 1

0

刚刚找到了一种使用 dataPoints 中的 name 属性的方法:

var chart = new CanvasJS.Chart("chartContainer",
{
    animationEnabled: true,
    theme: "theme2",
    data: [
        {        
            type: "doughnut",
            startAngle:270 ,
            toolTipContent: "{name}: {y}",
            dataPoints: [
                {  y: 2, name: "L1"},
                {  y: 3, name: "L2"},
                {  y: 8, name: "L3"}

            ]
        }
    ]
});

chart.render();

http://canvasjs.com/docs/charts/chart-options/data/datapoints/

于 2015-07-07T08:54:53.300 回答