javascript - 使用 angular-chart.js 时如何增加图例和图表之间的空间?
问题描述
我正在使用 angular-chart.js 创建一个图表,并增加了相当多的点大小(默认为 5 为 8),以提高我们用户的可见性。这样做会使折线图的点与图例重叠。
解决方案
这是此答案中修复的实现:https ://stackoverflow.com/a/55411810 ,来自这篇文章:Chart.js - 增加图例和图表之间的间距...
在您设置的任何控制器中,添加一个angular.module('graph').config()
(“.config 块”),以便您可以访问ChartProvider
并通过它访问Chart
对象:
angular.module('graph')
.config(function ($windowProvider, ChartJsProvider) {
// Storing ChartJs on $window via $windowProvider.$get() in case
// we need to do other stuff from directly within a Controller.
let
ChartJs =
$windowProvider.$get().ChartJs =
ChartJsProvider.$get().Chart;
// Ref.: https://stackoverflow.com/a/55411810/7577883
ChartJs.Legend.prototype.afterFit = function () {
// You can change the height to whatever pixel value you need.
this.height = this.height + 32;
};
})
.controller('graphController', graphController);
function graphController($window) {
// Example of your controller needs to do and/or options it needs to set.
$scope.graphingData = [ /* Your Data */ ];
$scope.graphingSeries = [ /* The Series */ ];
$scope.graphingOptions = [ /* ChartJs Options */ ];
$scope.graphingColours = [ /* Chart Colour Scheme */ ];
}
在模板中:
<canvas
id="line"
class="chart chart-line"
chart-data="graphingData"
chart-series="graphingSeries"
chart-options="graphingOptions"
chart-colors="graphingColours"
></canvas>
我会将其添加为对引用答案的评论,但我的帐户代表。作为一个新帐户太低了。
我真的希望这些信息可以帮助那里的人!感谢那些让我走上正确道路的人!!!
推荐阅读
- angular - Angular Material Icon Button 会产生涟漪,但不会触发点击
- linux - 试图用空格获取文件名和文件夹名
- javascript - 使用 Jest 使用 useReducer 测试 React Provider 包装的组件
- ios - 另一个函数中的 Swift UITableview 自定义单元格 Imageview 颜色更改
- laravel - 如何将linehieght插件添加到ckeditor
- php - 在不使用 PHP 函数的情况下确定给定数字是否为整数
- javascript - 我不知道为什么我的 npm 没有响应 var uc = require('upper-case');
- python - 分组为 15 分钟
- java - 如何检查表的所有休眠查询是否具有特定列的条件?
- angular - 登录用户组