【发布时间】:2015-07-27 06:26:55
【问题描述】:
我想知道我们是否有现成的聚合物 1.0 图表元素。我正在尝试将 chart-doughnut (https://github.com/robdodson/chart-elements/) 从使用 Chart.js 脚本的聚合物 0.5 迁移到 1.0。
我已通过以下方式迁移了 chart-doughnut.html 文件:
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="chart-js-import.html">
<!--
Pie and doughnut charts are probably the most commonly used chart there are. They are divided into segments, the arc of each segment shows a the proportional value of each piece of data.
They are excellent at showing the relational proportions between data.
Pie and doughnut charts in are effectively the same class in Chart.js, but have one different default value - their percentageInnerCutout. This equates what percentage of the inner should be cut out. This defaults to 0 for pie charts, and 50 for doughnuts.
They are also registered under two aliases in the Chart core. Other than their different default value, and different alias, they are exactly the same.
##### Example
<chart-doughnut values="[30, 50, 100, 40, 120]"></chart-doughnut>
@element chart-doughnut
@blurb A chart for showing the relational proportions between data.
@status alpha
@homepage http://robdodson.github.io/chart-elements
-->
<dom-module id="chart-doughnut">
<template>
<canvas id="canvas" width="{{width}}" height="{{height}}"></canvas>
</template>
<script>
Polymer({
is: 'chart-doughnut',
properties: {
colors: {
type: Array,
value: ['#F7464A',
'#46BFBD',
'#FDB45C',
'#949FB1',
'#4D5360'
];
},
notify: true,
observer: 'updateChart'
},
height: {
notify: true,
observer: 'resize'
},
options: {
type: Object,
value: {};
},
notify: true,
observer: 'updateChart'
},
values: {
type: Array,
value: [
30,
50,
100,
40,
120
];
},
notify: true,
observer: 'updateChart'
},
width: {
notify: true,
observer: 'resize'
}
},
resize: function () {
if (this.chart) {
this.updateChart();
}
},
updateChart: function () {
this.async(function () {
if (this.chart) {
console.log("CHARTTTT"+this.chart);
this.chart.destroy(); // Bindings don't seem to be taking effect properly so
// manually set width and height
// Bindings don't seem to be taking effect properly so
// manually set width and height
this.$.canvas.setAttribute('width', this.width);
this.$.canvas.setAttribute('height', this.height);
}
this.data = [];
this.values.forEach(function (val, i) {
this.data.push({
color: this.colors[i],
value: val
});
}, this);
this.ctx = this.$.canvas.getContext('2d');
this.chart = new Chart(this.ctx).Doughnut(this.data, this.options);
}, null, 0);
}
});
</script>
</dom-module>
但是在使用它时,我在 Chart.js 中收到以下错误
未捕获的 IndexSizeError:无法在“CanvasRenderingContext2D”上执行“arc”:提供的半径 (-0.5) 为负数。 Chart.js:1226 0 0 -0.5 4.71238898038469 4.713461589614612
请建议。
【问题讨论】:
标签: javascript polymer-1.0 chart.js