首页 文章

Chart.js - >在饼图上显示%

提问于
浏览
1

我正在尝试显示每个用户代表的饼图的百分比 . 我在看的时候发现了tooltipTemplate代码,但它似乎没有工作,我没有得到任何错误 . 以前有人试过这个吗?我的图表加载正常,而不是百分比 .

我有以下代码,并链接numbers.js脚本(如建议) -

// this array is necessary for generating links
    var ids = [
        @foreach($user->frontline as $person)
            {
                id: {{ $person->id }},
                label: "{{ $person->full_name }}",
                value: {{ $person->business_month_volume }},
                tooltipTemplate: " <%if (segmentLabel){%><%=segmentLabel%>: <%}%><%= numeral(value).format('($0,0[.]00)') %> - <%= numeral(circumference / 6.283).format('(0[.][00]%)') %>"
            },
        @endforeach
    ];

    // pie chart
    var data = [
        @foreach($user->frontline as $person)
            {
                id: {{ $person->id }},
                value: {{ $person->business_year_volume }},
                color: "{{ $colors[$index]['primary'] }}",
                highlight: "{{ $colors[$index]['highlight'] }}",
                label: "{{ $person->full_name }}",
                labelColor: "black",
                labelFontSize: '16px',
                segmentLabel: '16px'
            },
            <?php
                if($index < count($colors) -1) $index ++;
                else $index = 0;
            ?>
        @endforeach
    ];

2 回答

  • 0

    我读到了ChartNew.JS,它应该包含你需要的功能(参见这里的示例:http://fvancop.github.io/ChartNew.js/) . 我自己还没用过,但我认为它可以帮到你!

  • 0

    你可以转换数据,这样就可以增加到100个 . 所以如果你有一个水果饼图,你有6个橘子,7个苹果,3个香蕉 . 你将有16个水果总数,所以使橙色的部分= 6/16,苹果= 7/16和3/16香蕉

相关问题