<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 中无法获得条形图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                    <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'>