在angular-chart.js甜甜圈图上渲染图例 [英] Render a legend on angular-chart.js doughnut chart

查看:161
本文介绍了在angular-chart.js甜甜圈图上渲染图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了angular-chart.js文档,并创建了一个图表,但是无法使用它来显示图例。我不明白为什么它不起作用。



文档:



我也曾尝试在控制器中为图例定义一个数组,

  $ scope.legend = [ complete, incomplete] 

每个在其他SO问题中接受的答案, chart-legend = true 应该足以使其正常工作。



有人对这个库有经验并有想法吗?

解决方案

如果您使用的是基于chart.js的1.0.0-alpha分支,2,正确的语法是:

  $ scope.options = {legend:{display:true}}; 

并在您的html

<画布id = pie
class = chart chart-pie
chart-data = data
chart-labels = labels
chart-options = options>
< / canvas>


I've followed angular-chart.js documentation, and created a chart, but am unable to render a legend with it. I don't understand why its not working.

Documentation: http://jtblin.github.io/angular-chart.js/
Similar SO question: How to color legend in angular-chart.js

<div class="panel-body" ng-controller="CircleCtrl" style="display: block;">
    <div class="chart-container" style="width:400px; height:200px;">
        <canvas id="doughnut"
            class="chart chart-doughnut"
            chart-data="data"
            chart-labels="labels"
            chart-colours="colours"
            chart-legend="true">
        </canvas> 
    </div>
</div>  

I've also tried defining an array for legend in the controller,

$scope.legend = ["complete", "incomplete"]

Per the accepted answer in the other SO question, chart-legend="true" should be enough to make it work.

Does anyone have experience with this library and have an idea how to solve this issue?

解决方案

If you're using the 1.0.0-alpha branch based on chart.js 2, the correct syntax is:

$scope.options = {legend: {display: true}};

and in your html

<canvas id="pie"
            class="chart chart-pie"                
            chart-data="data"
            chart-labels="labels"
            chart-options="options">
 </canvas>

这篇关于在angular-chart.js甜甜圈图上渲染图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆