<small id='wKubP'></small><noframes id='wKubP'>

  • <legend id='wKubP'><style id='wKubP'><dir id='wKubP'><q id='wKubP'></q></dir></style></legend>
    <i id='wKubP'><tr id='wKubP'><dt id='wKubP'><q id='wKubP'><span id='wKubP'><b id='wKubP'><form id='wKubP'><ins id='wKubP'></ins><ul id='wKubP'></ul><sub id='wKubP'></sub></form><legend id='wKubP'></legend><bdo id='wKubP'><pre id='wKubP'><center id='wKubP'></center></pre></bdo></b><th id='wKubP'></th></span></q></dt></tr></i><div id='wKubP'><tfoot id='wKubP'></tfoot><dl id='wKubP'><fieldset id='wKubP'></fieldset></dl></div>
    • <bdo id='wKubP'></bdo><ul id='wKubP'></ul>

  • <tfoot id='wKubP'></tfoot>

        在 React Js 中工作的 Chart js 中无法获得条形图颜色

        Can#39;t get bar chart colors in Chart js working in React Js(在 React Js 中工作的 Chart js 中无法获得条形图颜色)
          <tbody id='v4x2H'></tbody>
        <i id='v4x2H'><tr id='v4x2H'><dt id='v4x2H'><q id='v4x2H'><span id='v4x2H'><b id='v4x2H'><form id='v4x2H'><ins id='v4x2H'></ins><ul id='v4x2H'></ul><sub id='v4x2H'></sub></form><legend id='v4x2H'></legend><bdo id='v4x2H'><pre id='v4x2H'><center id='v4x2H'></center></pre></bdo></b><th id='v4x2H'></th></span></q></dt></tr></i><div id='v4x2H'><tfoot id='v4x2H'></tfoot><dl id='v4x2H'><fieldset id='v4x2H'></fieldset></dl></div>

        <tfoot id='v4x2H'></tfoot><legend id='v4x2H'><style id='v4x2H'><dir id='v4x2H'><q id='v4x2H'></q></dir></style></legend>

        <small id='v4x2H'></small><noframes id='v4x2H'>

            <bdo id='v4x2H'></bdo><ul id='v4x2H'></ul>

                1. 本文介绍了在 React Js 中工作的 Chart js 中无法获得条形图颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  This is my first time working with Chart Js and I managed to get it displaying on my page but the keys 'label', 'backgroundColor', 'borderColor', and 'borderWidth' won't display. The keys 'labels' and 'data' work just fine as I can see the labels and the bars in the chart. I tried assigning the non-displaying keys to variables just like 'labels' and 'data' to see if it would work that way but no luck. I also tried passing hex colors and regular color names like red, blue, etc. but that didn't work either. If anyone could provide some assistance it would be greatly appreciated, thanks!

                  'use strict';
                  
                  import React, { Component } from 'react';
                  
                  var Chart = require("react-chartjs").Bar;
                  
                  class BarChart extends Component {
                  
                    capitalize(name) {
                      return name.charAt(0).toUpperCase() + name.slice(1);
                    }
                  
                    render() {
                  
                      var pokeLabels = this.props.stats.map((label) => {
                        return this.capitalize(label.stat.name)
                      })
                  
                      var pokeDataSet = this.props.stats.map((set) => {
                        return set.base_stat
                      })
                  
                      console.log(this.props.stats);
                  
                      var data = {
                        labels: pokeLabels,
                        datasets: [
                          {
                              label: 'Pokemon Stats',
                              backgroundColor: [
                                  'rgba(255, 99, 132, 0.2)',
                                  'rgba(54, 162, 235, 0.2)',
                                  'rgba(255, 206, 86, 0.2)',
                                  'rgba(75, 192, 192, 0.2)',
                                  'rgba(153, 102, 255, 0.2)',
                                  'rgba(255, 159, 64, 0.2)'
                              ],
                              borderColor: [
                                  'rgba(255,99,132,1)',
                                  'rgba(54, 162, 235, 1)',
                                  'rgba(255, 206, 86, 1)',
                                  'rgba(75, 192, 192, 1)',
                                  'rgba(153, 102, 255, 1)',
                                  'rgba(255, 159, 64, 1)'
                              ],
                              borderWidth: 1,          
                              data: pokeDataSet
                          }
                        ]
                      }
                  
                      return (
                        <div className='row'>
                          <div className='col-xs-12 col-sm-offset-3 col-xs-offset-0'>
                            <Chart data={data} width="600" height="250" redraw />
                          </div>
                        </div>
                      );
                    }   
                  
                  }
                  
                  export default BarChart;
                  

                  解决方案

                  So I was able to get the colors working by doing this:

                      datasets: [
                          {
                              label: "My First dataset",
                              fillColor: ["rgba(0,10,220,0.5)","rgba(220,0,10,0.5)","rgba(220,0,0,0.5)","rgba(120,250,120,0.5)" ],
                              strokeColor: "rgba(220,220,220,0.8)", 
                              highlightFill: "rgba(220,220,220,0.75)",
                              highlightStroke: "rgba(220,220,220,1)",
                              data: pokeDataSet
                          }
                  

                  Hope this can help someone who has a similar issue!

                  这篇关于在 React Js 中工作的 Chart js 中无法获得条形图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                  Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                  How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                  Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                  Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                  How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)
                    <i id='nR7VN'><tr id='nR7VN'><dt id='nR7VN'><q id='nR7VN'><span id='nR7VN'><b id='nR7VN'><form id='nR7VN'><ins id='nR7VN'></ins><ul id='nR7VN'></ul><sub id='nR7VN'></sub></form><legend id='nR7VN'></legend><bdo id='nR7VN'><pre id='nR7VN'><center id='nR7VN'></center></pre></bdo></b><th id='nR7VN'></th></span></q></dt></tr></i><div id='nR7VN'><tfoot id='nR7VN'></tfoot><dl id='nR7VN'><fieldset id='nR7VN'></fieldset></dl></div>

                      <tbody id='nR7VN'></tbody>
                  1. <legend id='nR7VN'><style id='nR7VN'><dir id='nR7VN'><q id='nR7VN'></q></dir></style></legend>

                        • <bdo id='nR7VN'></bdo><ul id='nR7VN'></ul>

                            <tfoot id='nR7VN'></tfoot>

                            <small id='nR7VN'></small><noframes id='nR7VN'>