Bootstrap Chart组件使用分享
图表组件Chart.js是Bootstrap比较好用的组件之一,与一款收费的组件highchart类似,效果上来看免费与收费的产品相差还是有一点点的,不过功能上差不多能满足我们项目的需要。下面这段JS脚本主要是为了方便生成一个图表的配置而写的方法
/**
* 获取一个新的chart配置项
* @param color rgba颜色
* @param type 图表类型:line,bar,radar,polarArea,pie,doughnut
* @param title 显示图表的标题
* @param label 图表的标签,鼠标移到图表某个数据点时显示的提示文字
* @param categories 一般是X轴的内容
* @param data 一般是Y轴的数据
* @returns 返回图表的配置参数
*/
function getNewConfig(color,type,title,label,categories,data)
{
var background = color;
var config = {
type: type,
options: {
responsive: true,
legend: {
display: false,
position:'bottom'
},
hover: {
mode: 'label'
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: 'Value'
}
}]
},
title: {
display: true,
text: title
}
}
}; var dataset = {
label: label,
data: data,
fill: false,
borderDash: [5, 5],
borderColor : background,
backgroundColor : background,
pointBorderColor : background,
pointBackgroundColor : background,
pointBorderWidth : 1
};
var data = {
labels:categories,
datasets: [dataset]
};
config.data = data;
return config;
}
调用方法:
<canvas id="chart_weixinmember" height="100"></canvas>
var color = 'rgba(51,126,255,0.5)';
var categories = ["2016-04-22","2016-04-23","2016-04-24","2016-04-25","2016-04-26","2016-04-27","2016-04-28"];
var data = [0,0,0,0,1,0,0];
var config = getNewConfig(color,'line','最近7天微信会员增长情况','当天新增微信会员',categories,data);
var ctx = document.getElementById("chart_weixinmember").getContext("2d");
var weixinMemberCountChart = new Chart(ctx, config);
显示的效果:

说明:使用上面的代码需要引用Chart.js,
Chart中文网站以及文档:
http://www.bootcss.com/p/chart.js/
http://www.bootcss.com/p/chart.js/docs/
Chart英文网站及文档:
www.chartjs.org
www.chartjs.org/docs
Bootstrap Chart组件使用分享的更多相关文章
- JS组件系列——Bootstrap Select2组件使用小结
前言:在介绍select组件的时候,博主之前分享过一篇JS组件系列——两种bootstrap multiselect组件大比拼,这两个组件的功能确实很强大,只可惜没有图文结合的效果(也就是将图片放入到 ...
- AngularJs的UI组件ui-Bootstrap分享(一)
最近几个月学习了AngularJs和扩展的UI组件,并在公司小组内做了一次分享交流,感觉很有收获,在此记录下个人的学习心得. 目录: AngularJs的UI组件ui-Bootstrap分享(一) A ...
- AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel
Carousel指令是用于图片轮播的控件,引入ngTouch模块后可以在移动端使用滑动的方式使用轮播控件. <!DOCTYPE html> <html ng-app="ui ...
- AngularJs的UI组件ui-Bootstrap分享(十三)——Progressbar
进度条控件有两种指令,第一种是uib-progressbar指令,表示单一颜色和进度的一个进度条.第二种是uib-bar和uib-progress指令,表示多种颜色和多个进度组合而成的一个进度条. 这 ...
- AngularJs的UI组件ui-Bootstrap分享(十二)——Rating
Rating是一个用于打分或排名的控件.看一个最简单的例子: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo" x ...
- AngularJs的UI组件ui-Bootstrap分享(十一)——Typeahead
Typeahead指令是一个用于智能提示或自动完成的控件,就像Jquery的AutoComplete控件一样.来看一个最简单的例子: <!DOCTYPE html> <html ng ...
- AngularJs的UI组件ui-Bootstrap分享(十)——Model
Model是用来创建模态窗口的,但是实际上,并没有Model指令,而只有$uibModal服务,创建模态窗口是使用$uibModal.open()方法. 创建模态窗口时,要有一个模态窗口的模板和对应的 ...
- AngularJs的UI组件ui-Bootstrap分享(九)——Alert
alert指令会在页面上显示一条提示消息,效果是这样: 代码为: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo" ...
- AngularJs的UI组件ui-Bootstrap分享(八)——Tooltip和Popover
tooltip和popover是轻量的.可扩展的.用于提示的指令.对于移动端来讲,这两个指令虽然可以正常工作,但是从用户体验的角度并不推荐使用. 先说tooltip,tooltip有三种使用方式: ( ...
随机推荐
- lr中switch的应用
Action() { char *time; int i,j,length; time=lr_eval_string("{testtime}"); lr_error_message ...
- hdu1159 最长公共子序列
Common Subsequence Problem Description A subsequence of a given sequence is the given sequence with ...
- Flume interceptor 使用注意事项
1. 在使用 Regex Filtering Interceptor的时候一个属性是excludeEvents 当它的值为true 的时候,过滤掉匹配到当前正则表达式的一行 当它的值为false的时候 ...
- Codeforces Round #334 (Div. 2)
水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...
- iOS学习13之OC NSString类
C语言中,字符串是有char(ASC||码)字符组成. OC中,字符串是由unichar(Unicode)字符组成. 1.字符串(NSString) NSString:不可变字符串,即:创建以后,内容 ...
- python 代码片段19
#coding=utf-8 # 函数 def foo(x): print x foo(123) # import httplib def check_web_server(host,port,path ...
- FastDFS原理
转自:http://blog.chinaunix.net/uid-20196318-id-4058561.html 开源的轻量级分布式文件系统,由跟踪服务器(tracker server).存储服务器 ...
- Window.location
1.location 对象 // 假设当前url是 http://localhost/rpc/plugin.php#hash?a=aaa&b=bbb alert(window.location ...
- Recurrent Neural Network(循环神经网络)
Reference: Alex Graves的[Supervised Sequence Labelling with RecurrentNeural Networks] Alex是RNN最著名变种 ...
- Leetcode Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted ...