Last active
March 15, 2017 15:57
-
-
Save giscafer/eabd9e58fe8d92165700d4ec78b996ad to your computer and use it in GitHub Desktop.
primeng bar chart 宽度设置方式(Chart.js how to set the width for a bar chart)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by giscafer on 2017/3/15. | |
*/ | |
import {Component} from '@angular/core'; | |
import {UIChart} from 'primeng/primeng'; | |
@Component({ | |
selector: 'cool-chart', | |
template:`<p-chart type="bar" [data]="data" [options]="options"></p-chart>`, | |
directives: [ UIChart ] | |
}) | |
export class BarChartComponent { | |
data: any; | |
options: any; | |
constructor() { | |
this.data = { | |
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | |
datasets: [ | |
{ | |
label: 'My First dataset', | |
backgroundColor: '#42A5F5', | |
borderColor: '#1E88E5', | |
data: [65, 59, 80, 81, 56, 55, 40] | |
}, | |
{ | |
label: 'My Second dataset', | |
backgroundColor: '#9CCC65', | |
borderColor: '#7CB342', | |
data: [28, 48, 40, 19, 86, 27, 90] | |
} | |
] | |
}; | |
this.options = { | |
title: { | |
display: true, | |
text: '这是一个bar', | |
fontSize: 16 | |
}, | |
//see http://www.chartjs.org/docs/#bar-chart-barpercentage-vs-categorypercentage | |
scales: { | |
xAxes: [{ | |
stacked: false, | |
categoryPercentage: 0.5, //宽度设置属性 | |
barPercentage: 0.5 //宽度设置属性 | |
}], | |
yAxes: [{ | |
stacked: false | |
}] | |
}, | |
legend: { | |
position: 'top', | |
labels: { | |
fontColor: 'rgb(255, 99, 132)' | |
} | |
} | |
}; | |
} | |
} |
Author
giscafer
commented
Mar 15, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment