首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有聚合物包装器图表元素的charts.js堆叠条形图

具有聚合物包装器图表元素的charts.js堆叠条形图
EN

Stack Overflow用户
提问于 2016-08-08 17:48:11
回答 1查看 277关注 0票数 1

我一直试图让堆叠的选项在chart.js的图表元素聚合物包装器中工作,但没有成功,我尝试了以下代码,但它给了我一个空白。这是我的专栏-chart.html

<link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" href="../bower_components/jquery/dist/jquery.min.js"> <link rel="import" href="../bower_components/chart-elements/chart-bar.html">

代码语言:javascript
复制
 <chart-bar id="alarmsChart" data="[[data]]" style="width: 600px; height: 360px;"></chart-bar>

代码语言:javascript
复制
      Polymer({
               is: 'column-chart',
               ready: function () {
                 this.data = {
                   type: 'bar',
                   data: {
                       labels: ["January", "February", "March", "April", "May", "June", "July"],
                      datasets: [{
                        label: 'Dataset 1',
                        backgroundColor: "rgba(5,141,199,0.5)",
                        data: [100, 110, 95, 100, 100, 102, 101],
                        stack: 1
                     }, {
                        label: 'Dataset 2',
                        backgroundColor: "rgba(80,180,50,0.5)",
                       data: [94, 96, 98, 94, 97, 97, 96],
                       stack: 1
                }, {
                       label: 'Dataset 3',
                       backgroundColor: "rgba(237,86,27,0.5))",
                       data: [98, 97, 87, 85, 99, 84, 94],
                       stack: 1
                      }]
                  },
                options: {
                    responsive: true,
                    scales: {
                        xAxes: [{
                            stacked: true,
                        }],
                        yAxes: [{
                            stacked: true
                        }]
                        }
                    }
        }}
       });
</script>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-08 20:09:21

1)在你的第三个背景颜色中有一个多余的对比:

代码语言:javascript
复制
backgroundColor: "rgba(237,86,27,0.5))",

应该是:

代码语言:javascript
复制
backgroundColor: "rgba(237,86,27,0.5)",

2)尝试在data对象中插入data属性,这是多余的。

3)您不必定义type: 'bar'属性,因为它是由控件的名称设置的。

4)对于options属性,需要单独设置options对象:

代码语言:javascript
复制
<dom-module id="column-chart">

    <template>
        <div>
            <chart-bar data="[[data]]" options="[[options]]"></chart-bar>
        </div>
    </template>

    <script>
        Polymer({
            is: 'column-chart',
            ready: function() {

                this.data = {
                    labels: ["January", "February", "March", "April", "May", "June", "July"],
                    datasets: [
                    {
                        label: 'Dataset 1',
                        backgroundColor: "rgba(5,141,199,0.5)",
                        data: [100, 110, 95, 100, 100, 102, 101],
                        stack: 1
                    }, 
                    {
                        label: 'Dataset 2',
                        backgroundColor: "rgba(80,180,50,0.5)",
                        data: [94, 96, 98, 94, 97, 97, 96],
                        stack: 1
                    }, 
                    {
                        label: 'Dataset 3',
                        backgroundColor: "rgba(237,86,27,0.5)",
                        data: [98, 97, 87, 85, 99, 84, 94],
                        stack: 1
                    }]
                }

                this.options = {
                    responsive: true,
                    scales: {
                        xAxes: [{
                            stacked: true,
                        }],
                        yAxes: [{
                            stacked: true
                        }]
                    }
                }   
            }
        });
    </script>

</dom-module>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38826017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档