[JS]漂亮的chart.js实例——js图表
<div style="width:600px; height:450px;">
<canvas id="canvas"></canvas>
</div>
<script type="text/javascript" src="Chart.min.js"></script>
<script type="text/javascript">
var ctx = new Chart(document.getElementById("canvas").getContext("2d"));
var options = {
scaleLineColor : "rgba(255,0,0,.1)",
scaleGridLineColor : "rgba(255,0,0,.05)"
};
// 线型图
var LineChart = {
labels: ["Ruby", "jQuery", "Java", "ASP.Net", "PHP"],
datasets: [{
fillColor: "rgba(151,249,190,0.5)",
strokeColor: "rgba(255,255,255,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
data: [10, 20, 30, 40, 50]
}, {
fillColor: "rgba(252,147,65,0.5)",
strokeColor: "rgba(255,255,255,1)",
pointColor: "rgba(173,173,173,1)",
pointStrokeColor: "#fff",
data: [28, 68, 40, 19, 96]
}]
};
/*
* 不同的chart.js版本调用方法是不一样的;
* 比如现在用的2.6.0就应该是第二种(未屏蔽的)方法;
*/
//var myLineChart = ctx.Line(LineChart, options);
var myLineChart = new Chart(ctx, {
type:'line',
data:LineChart,
options:options
});
// 条形图
var BarChart = {
labels: ["Ruby", "jQuery", "Java", "ASP.Net", "PHP"],
datasets: [{
fillColor: "rgba(151,249,190,0.5)",
strokeColor: "rgba(255,255,255,1)",
data: [13, 20, 30, 40, 50]
}, {
fillColor: "rgba(252,147,65,0.5)",
strokeColor: "rgba(255,255,255,1)",
data: [28, 68, 40, 19, 96]
}]
};
//var myBarChart = ctx.Bar(BarChart, options);
// 饼状图
var pieChart = [
{value: 40, color: "#fcc79c"},
{value: 30, color: "#beefd2"},
{value: 90, color: "#ffddfb"},
];
//var myPieChart = ctx.Pie(pieChart);
// 环状图
var doughnutChart = [
{value: 60, color: "#fcc79e"},
{value: 30, color: "#beefd2"},
{value: 50, color: "#ffddfb"},
{value: 120, color: "#cdecff"},
{value: 90, color: "#fff5bc"}
];
//var myRingChart = ctx.Doughnut(doughnutChart);
</script>
标签: JS
日历
最新微语
- 有的时候,会站在分叉路口,不知道向左还是右
2023-12-26 15:34
- 繁花乱开,鸟雀逐风。心自宁静,纷扰不闻。
2023-03-14 09:56
- 对于不可控的事,我们保持乐观,对于可控的事情,我们保持谨慎。
2023-02-09 11:03
- 小时候,
暑假意味着无忧无虑地玩很长一段时间,
节假意味着好吃好喝还有很多长期不见的小朋友来玩...
长大后,
这是女儿第一个暑假,
一个半月...
2022-07-11 08:54
- Watching the autumn leaves falling as you grow older together
2018-10-25 09:45
分类
最新评论
- Goonog
i get it now :) - 萧
@Fluzak:The web host... - Fluzak
Nice blog here! Also... - Albertarive
In my opinion you co... - ChesterHep
What does it plan? - ChesterHep
No, opposite. - mojoheadz
Everything is OK!... - Josephmaigh
I just want to say t... - ChesterHep
What good topic - AnthonyBub
Certainly, never it ...
发表评论: