<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 中无法获得条形图颜色

        时间:2023-11-01
          <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.如何更改“标签"的字体样式大批? 下一篇:Chart.js PolarArea 图表.将标签更改为 45 度角

                  相关文章

                    <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>

                  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'>