[英]Overlapping Legends on Angular-Chart's Piechart
我正在使用角度图(目的是简化显示图表之类的工作)。 到目前为止, 这非常简单 ,我能够使我的饼图完美地呈现出来。
HTML:
<canvas id="pie" class="chart chart-pie"
chart-data="data" chart-labels="labels" chart-legend="true">
</canvas>
Javascript:
angular.module("app", ["chart.js"]).controller("PieCtrl", function ($scope) {
$scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
$scope.data = [300, 500, 100];
});
但是,由于我现在尝试包括图表的图例,所以我遇到了一个问题。 我的图例标签重叠,并且我不确定如何解决(如果确实有解决方法?!)。 非常感谢任何帮助,:)
更新:
.col-xs-12.col-sm-12.col-md-6
.panel.panel-primary(ng-controller='pieChartController')
.panel-heading
h2.panel-title Title
.panel-body
canvas#pie.chart.chart-pie(chart-data='data', chart-labels='labels', chart-legend='true', chart-options='options')
更新:
在检查饼图的图例后,我发现它遵循以下CSS规则:
.chart-legend,
.bar-legend,
.line-legend,
.pie-legend,
.radar-legend,
.polararea-legend,
.doughnut-legend {
list-style-type: none;
margin-top: 5px;
text-align: center;
/* NOTE: Browsers automatically add 40px of padding-left to all lists, so we should offset that, otherwise the legend is off-center */
-webkit-padding-start: 0;
/* Webkit */
-moz-padding-start: 0;
/* Mozilla */
padding-left: 0;
/* IE (handles all cases, really, but we should also include the vendor-specific properties just to be safe) */
}
在angular-chart.css中。
ul,
ol {
margin-top: 0;
margin-bottom: 10px;
}
在bootstrap.css中。
.chart-legend li,
.bar-legend li,
.line-legend li,
.pie-legend li,
.radar-legend li,
.polararea-legend li,
.doughnut-legend li {
display: inline-block;
white-space: nowrap;
position: relative;
margin-bottom: 4px;
border-radius: 5px;
padding: 2px 8px 2px 28px;
font-size: smaller;
cursor: default;
}
在angular-chart.js中。
供以后参考,以防万一有人遇到与我相同的奇怪问题,...
我已经检查并仔细检查了一下,可以确认我确实在使用Chart.js
和angular-chart.js
的最新版本(@ J.Titus在他的Plunkr中也使用了最新版本)。
"chart.js": "^1.0.2"
"angular-chart.js": "~0.8.8"
但是,奇怪的是,我发现确实有些奇怪。
我正在检查您的Plunkr上的元素,希望找到有什么不同的线索。 我在@ J.Titus的Plunkr上发现的:
<span style="background-color:rgba(151,187,205,1)"></span> Download sales
我的是:
<span style="background-color:rgba(151,187,205,1)">Download sales</span>
为了更正此问题,我研究了Chart.js
并将所有出现的legendTemplate
( ctrl + F
是您最好的朋友!)更改为以下内容:
"<ul class=\\"<%=name.toLowerCase()%>-legend\\"><% for (var i=0; i<segments.length; i++){%><li><span style=\\"background-color:<%=segments[i].fillColor%>\\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
这会将标签文本移出<span>
标记,从而有效解决了重叠问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.