[英]It is possible to change the color of periphery of Pie Chart in Chart.js?
Hi I'm making a pie chart using Chart.js. 嗨,我正在使用Chart.js制作饼图。 I have a small issue about styling.
我有一个关于样式的小问题。 The background of pie chart is purple and I want to make the periphery of pie chart purple.
饼图的背景为紫色,我想将饼图的外围设为紫色。 Default color is white.
默认颜色是白色。
Is it possible to change the color of periphery from default color? 是否可以将外围颜色从默认颜色更改?
Current view 目前来看
This is the current view. 这是当前视图。 Periphery is white.
外围是白色的。 I want to change it to purple to assimilate it to the background.
我想将其更改为紫色以将其吸收到背景中。
Code 码
export default class Categories extends React.Component{
constructor(props){
super(props);
this.state = {
slideOpen : false,
piData : piData
}
this.handleClick = this.handleClick.bind(this);
this.update = this.update.bind(this);
}
handleClick(){
this.setState({
slideOpen : !this.state.slideOpen
})
console.log(!this.state.slideOpen)
}
update() {
var piData;
this.setState({
piData : piData
})
console.log('data' + piData)
}
render(){
console.log('check' + piData)
const CategoriesPanel = this.state.slideOpen? "slideOpen" : "";
const { length } = this.props
console.log( 'result' + piData )
var totalData = piData + piData2 + piData3 + piData4 + piData5;
let newpiData = function() {
return parseInt((piData / totalData ) * 100 ) };
let newpiData2 = function() {
return parseInt((piData2 / totalData ) * 100) };
let newpiData3 = function() {
return parseInt((piData3 / totalData ) * 100) };
let newpiData4 = function() {
return parseInt((piData4 / totalData ) * 100) };
let newpiData5 = function() {
return parseInt((piData5 / totalData ) * 100) };
console.log('update data ' + newpiData())
console.log('question item piData parent component' + piData)
const data = {
labels: [
'question1',
'question2',
'question3',
'question4',
'question5'
],
datasets: [{
data: [ newpiData() , newpiData2(), newpiData3(), newpiData4(), newpiData5()],
backgroundColor: [
'orange',
'blue',
'red',
'purple',
'green'
],
hoverBackgroundColor: [
'orange',
'blue',
'red',
'purple',
'green'
]
}]};
return(
<div>
<div id="chart" className={CategoriesPanel}>
<Pie style={{"fontSize" : "20px" }}data={data}/>
<div className="categoriesSlide" onClick={this.handleClick}>{this.state.slideOpen? <img src={Arrowup} alt="arrowup" className="arrowup" /> : <img src={Arrowdown} alt="arrowdown" className="arrowdown"/>}</div>
<button onClick={this.update} className="chartButton">Update Information</button></div>
<div className="clear">
<List />
<ListSecond />
<ListThird />
<ListFourth />
<ListFifth />
</div>
</div>
)
}
}
Yes, You can change border color.Use bordercolor
property for this. 是的,您可以更改边框颜色。为此使用
bordercolor
属性。 You need to use array of borderColor . 您需要使用borderColor数组。 Here borderColor array length is equal to No. of pie chart slices
这里borderColor数组的长度等于饼图切片的数量
borderColor:['purple','purple','purple','purple','purple']
datasets: [{
data: [ newpiData() , newpiData2(), newpiData3(), newpiData4(), newpiData5()],
backgroundColor: [
'orange',
'blue',
'red',
'purple',
'green'
],
hoverBackgroundColor: [
'orange',
'blue',
'red',
'purple',
'green'
],
borderColor:['purple','purple','purple','purple','purple']
}]};
DEMO: https://codepen.io/anon/pen/NadBvz 演示: https : //codepen.io/anon/pen/NadBvz
DOCS: http://www.chartjs.org/docs/latest/charts/doughnut.html#dataset-properties DOCS: http : //www.chartjs.org/docs/latest/charts/doughnut.html#dataset-properties
It is as simple as that: http://www.chartjs.org/docs/latest/charts/doughnut.html#dataset-properties 就是这么简单: http : //www.chartjs.org/docs/latest/charts/doughnut.html#dataset-properties
const data = {
labels: [
'question1',
'question2',
'question3',
'question4',
'question5'
],
datasets: [{
data: [ newpiData() , newpiData2(), newpiData3(), newpiData4(), newpiData5()],
backgroundColor: [
'orange',
'blue',
'red',
'purple',
'green'
],
hoverBackgroundColor: [
'orange',
'blue',
'red',
'purple',
'green'
],
borderColor: ["purple", "purple", "purple", "purple", "purple"]
}]};
As you can see I have added borderColor
property for data set which is in fact array just like backgroundColor
. 如您所见,我为数据集添加了
borderColor
属性,该属性实际上是数组,就像backgroundColor
一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.