简体   繁体   English

是否可以删除段之间的边框,但在 react-chartjs-2 中保留饼图周围的边框?

[英]Is it possible to remove the border between the segments but leave the border around the pie chart in react-chartjs-2?

I am using react-chartjs-2 pie chart and I'd like to remove the lines(borders) between slices BUT I want to show the border around the chart.我正在使用 react-chartjs-2 饼图,我想删除切片之间的线(边框),但我想显示图表周围的边框。 Could someone tell me the way to do this?有人可以告诉我这样做的方法吗? Thanks in advance!提前致谢!

my code is like that now:我的代码现在是这样的:

import {Pie} from 'react-chartjs-2';
class App extends Component {
   render() {
      return (
         <div className='pieChartPositioner'>
            <Pie              
              height={36}
              width={36}
              data={{
                 datasets: [{
                     data: [20 , 80],
                     backgroundColor: ['red', 'green'],
                     borderColor: 'black',
                     borderWidth: 2,
                  }],
               }
             }/>
         </div>  
      )
   }
}

You need to set the borderWidth as 0 in the pie's arc configuration which by default is set to 2 .您需要在饼图的arc配置中将borderWidth设置为0 ,默认情况下设置为2

The arc configuration can be used in polar area, doughnut and pie charts and is set under the elements key.圆弧配置可用于极地图、圆环图和饼图,在elements键下设置。

You can change it by either:您可以通过以下任一方式更改它:

1. Setting the global arc options 1.设置全局arc选项

Chart.defaults.global.elements.arc.borderWidth = 0;

2. Or through the options object that you passed to the chart 2. 或者通过您传递给图表的options对象

 var options = { elements: { arc: { borderWidth: 0 } } };

See docs for more info.有关详细信息,请参阅文档

I am writing this because marked answer didn't help me, I guess it was changed in meanwhile.我写这篇文章是因为标记的答案对我没有帮助,我想它同时被改变了。

You need to set borderWidth inside datasets that you are passing to data prop.您需要在传递给data道具的数据集中设置borderWidth

Example:例子:

const data = {
        datasets: [{
          borderWidth:0,
          data: [9, 1],
          backgroundColor: ['#ffffff', '#000000'],
        }],
    };
    
    return (
      <Pie data={data} />
    )
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM