使用highchart的步骤.
访问量: 2881
refer to: http://www.highcharts.com/stock/demo,
1. 下载两个javascript 到你的 app/assets/javascript 目录
$ wget http://code.highcharts.com/highcharts.js $ wget http://code.highcharts.com/modules/exporting.js 然后, 在你的页面中,加上: <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
2. 代码中加上下面的js即可:
$('#chart_container').highcharts({
chart: {
type: 'column'
},
title: {
text: '竞品统计图'
},
xAxis: {
categories: ['360', '百度', '豌豆荚', 'hawei', 'oppo']
},
yAxis: {
min: 0,
title: {
text: '排名位置'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '' + this.x + '
' +
this.series.name + ': ' + this.y + '
'
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
},
series: [{
name: '优酷',
data: [5, 3, 4, 7, 2]
}, {
name: '土豆',
data: [2, 2, 3, 2, 1]
}, {
name: '爱奇异',
data: [3, 4, 4, 2, 5]
}]
});