highcharts 组合chart
/**
*制作 复杂的组合型的 charts
*
*@param [options] 图表的默认配置
*@dependence jQuery、highcharts
*@author wch
*/
function ComboCharts(options){ //定义jQuery变量,以防冲突
var $= jQuery; var _dom_id = ''; /*默认设置*/
var _def_optins = $.extend(true,{
title: {
text:''
},
xAxis: {
categories: []
},
labels: {
items: []
},
series:[],
credits:{
enabled:false
},
legend:{align:'center'},
tooltip: {
shared: true
}
},options); /**
* 更改默认设置,大多数情况下不会使用
*@param opt的具体值要参考 highcharts官方api
*/
function setOptions(opt){
_def_optins = $.extend(true,_def_optins,opt);
}
/**
*设置标题
*@param [title] 主标题
*@param [subtitle] 副标题
*/
function setTitle(title,subtitle){
title && $.extend(true,_def_optins,{title:{text:title}});
subtitle && $.extend(true,_def_optins,{subtitle:{text:subtitle}});
}
/**
*设置颜色数组
*@param colors 颜色数组
*/
function setColors(colors_arr){
colors_arr && (_def_optins.colors = colors_arr);
}
/**
*设置legend的位置
*@param align ---right,left,center
*@param vertical ---top,middle,bottom
*@param 不传入时,禁用legend
*/
function setLegendPosition(align,vertical){
if(align){
_def_optins.legend.align = align;
}
if(vertical){
_def_optins.legend.verticalAlign = vertical;
}
if(!align && !vertical){
_def_optins.legend.enabled = false;
}
}
/**
*在chart上面添加label
*@param label配置参见api
*/
function addLabel(label){
label && _def_optins.labels.items.push(label);
}
/**
*设置categories,通常情况下就是x轴
*@param categories 数组类型
*/
function setCategories(categories){
_def_optins.xAxis.categories = categories || [];
}
/**
* 添加一个图表
* @param series 参见api
*/
function addSeries(series){
series && _def_optins.series.push(series);
}
/**
*将chart写到页面上
*@param [dom_id] 是页面上元素的id
*/
function writeChart(dom_id){
//优先使用参数传递的dom_id
_dom_id = dom_id || _dom_id;
if(!noDataToDisplay()){
$('#'+_dom_id).highcharts(_def_optins);
}
}
/**
*设置dom_id
*@param dom_id 页面上元素的id
*/
function setDomId(dom_id){
_dom_id = dom_id;
} /**
*添加y轴
*@param [title] 标题
*@param [unit] 单位
*@param [offset] 传递true 或者 偏移值
*或者传递{}yAxis的配置,参见api
*/
function addYAxis(title,unit,offset){
title = title || '',unit = unit || '';
_def_optins.yAxis = _def_optins.yAxis || []; /*不是数组就转换为数组*/
if(!Array.isArray(_def_optins.yAxis)){
var arr = [];
arr.push(_def_optins.yAxis);
_def_optins.yAxis = arr;
} /*不是字符串,就是配置对象,直接放入*/
if(typeof title !== 'string'){
_def_optins.push(title);
}else{
var y = { // Secondary yAxis
title: {
text: title,
style: {
color: Highcharts.getOptions().colors[0]
}
},
labels: {
format: '{value}'+unit,
style: {
color: Highcharts.getOptions().colors[0]
}
}
};
/*判断传递的是offset还是opposite*/
if(offset && offset === true){
y.opposite = true;
}else{
y.offset = offset;
}
_def_optins.push(y);
}
} /**
* 重写highcharts的导出配置
*@param flag true --重写,false --禁用
*/
function setExporting(flag){
if(flag === false){
_def_optins.exporting = {enabled:false};
return;
}
Highcharts.setOptions({lang:{
contextButtonTitle:'导出菜单',
downloadJPEG:'导出为JPEG',
downloadPDF:'导出为PDF',
downloadPNG:'导出为PNG',
downloadSVG:'导出为SVG',
printChart:'打印'
}});
}
/**
*判断series是否有数据进行展现
*@return Boolean
*/
function noDataToDisplay(){
if(!_def_optins.series || _def_optins.series.length === 0){
$('#'+_dom_id).css({"vertical-align":"middle","text-align":"center","line-height":($('#'+_dom_id).height()+"px")}).html('没有数据进行展现!');
return true;
}
return false;
} return {
setOptions:setOptions,
addLabel:addLabel,
setCategories:setCategories,
addSeries:addSeries,
writeChart:writeChart,
setDomId:setDomId,
addYAxis:addYAxis,
setTitle:setTitle,
setColors:setColors,
setLegendPosition:setLegendPosition,
setExporting:setExporting
};
}
使用demo
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title> <script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../../js/h3charts.js"></script>
<script type="text/javascript">
$(function () { //$('#container').highcharts(
var opt =
{
chart: {
zoomType: 'xy'
},
title: {
text: 'Average Monthly Temperature and Rainfall in Tokyo'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: [{
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
}],
tooltip: {
shared: true
},
series: [{
type: 'column',
name: 'Jane',
data: [3, 2, 1, 3, 4]
}, {
type: 'column',
name: 'John',
data: [2, 3, 5, 7, 6]
}, {
type: 'column',
name: 'Joe',
data: [4, 3, 3, 9, 3]
}, {
type: 'spline',
name: 'Average',
data: [3, 2.67, 3, 6.33, 3.33],
marker: {
lineWidth: 2,
lineColor: Highcharts.getOptions().colors[3],
fillColor: 'white'
}
}, {
type: 'pie',
name: 'Total consumption',
data: [{
name: 'Jane',
y: 13,
color: Highcharts.getOptions().colors[0] // Jane's color
}, {
name: 'John',
y: 23,
color: Highcharts.getOptions().colors[1] // John's color
}, {
name: 'Joe',
y: 19,
color: Highcharts.getOptions().colors[2] // Joe's color
}],
center: [100, 80],
size: 100,
showInLegend: false,
dataLabels: {
enabled: false
}
}]
}
//);
var mychart = ComboCharts();
mychart.setTitle(opt.title.text,opt.subtitle.text);
mychart.setCategories(opt.xAxis[0].categories);
//mychart.addSeries(opt.series[0]);
//mychart.addSeries(opt.series[1]);
//mychart.addSeries(opt.series[2]);
//mychart.addSeries(opt.series[4]);
mychart.setColors(['#ff00ff','#A74442','#87A34C','#70568D','#4095AD','#D7813C',
'#f15c80', '#e4d354', '#8085e8', '#8d4653', '#91e8e1']);
mychart.setLegendPosition('left','middle');
mychart.addLabel({
html: 'sdfsdif',
style: {
left: '50px',
top: '18px',
color: Highcharts.getOptions().colors[0] || 'black'
}
});
mychart.setDomId("container");
mychart.setExporting(false);
mychart.writeChart();
}); </script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script> <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> </body>
</html>
highcharts 组合chart的更多相关文章
- Highcharts - Bar Chart & Column Chart
1. 条形图(Bar Chart)需要的数据格式类型如下: ["Luke Skywalker", "Darth Vader", "Yoda" ...
- Highcharts - Pie Chart
1. 饼状图(Pie Chart)示例: <div id="container" style="height: 400px"></div> ...
- 【HighCharts系列教程】三、图表属性——chart
一.chart属性说明 Chart是HighCharts图表中主要属性,包括了图表区域的颜色.线条.高度.宽度.对齐.图表类型等诸多属性,也是HighCharts图表中必须配置的属性之一. 配置cha ...
- Highcharts 测量图;Highcharts 圆形进度条式测量图;Highcharts 时钟;Highcharts 双轴车速表;Highcharts 音量表(VU Meter)
Highcharts 测量图 配置 chart.type 配置 配置 chart 的 type 为 'gauge' .chart.type 描述了图表类型.默认值为 "line". ...
- highcharts使用笔记
1.legend取消点击事件: 饼图:plotOptions.pie.point.events.legendItemClick = function() {return false;} 其他,如:pl ...
- Highcharts指南
摘要 Highcharts图表控件是目前使用最为广泛的图表控件.本文将从零开始逐步为你介绍Highcharts图表控件.通过本文,你将学会如何配置Highcharts以及动态生成Highchart图表 ...
- 相识Highcharts,几分钟玩转Highcharts
Highcharts是一个功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯js图表库. 官网:http://www.hcharts.cn/ 我觉得对于刚接触一个东西的新手来说,有时候对一个东西真 ...
- Highcharts结合PhantomJS在服务端生成高质量的图表图片
项目背景 最近忙着给部门开发一套交互式的报表系统,来替换原有的静态报表系统. 老系统是基于dotnetCHARTING开发的,dotnetCHARTING的优势是图表类型丰富,接口调用简单,使用时只需 ...
- highcharts图表中级入门之xAxis label:X(横)坐标刻度值过长截断多行(换行)显示问题说明
在使用highcharts图表的过程中,总会碰到这样一个很是棘手的问题,横坐标刻度值太长,在不换行显示的情况下显得格外拥挤.虽然针对这一问题是可以对其刻度值进行旋转以此来避开显示拥挤问题[如何让hig ...
随机推荐
- java多线程编程核心技术(二)--对象及变量的并发访问
1.方法内部的私有变量是线程安全的,实例变量是线程不安全的. 2.A线程先持有object对象的lock锁,B线程可以以异步的方式调用object对象中的非synchronized类型的方法. 3.A ...
- java中static学习总结
<<java编程思想>>: 1.static方法就是没有this的方法. 2.在static方法内部非静态方法. 3.在没有创建对象的前提下,可以通过类本身来调用static修 ...
- lombok中的@ToString注解作用
Lombok是一个很好的工具,节省了很多重写方法,而@ToString就是节省了ToString方法,lombok中@ToString就是节省了我们在模型中的冗余代码下面就来举个例子 import j ...
- 4、Java并发性和多线程-并发编程模型
以下内容转自http://ifeve.com/%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E6%A8%A1%E5%9E%8B/: 并发系统可以采用多种并发编程模型来实现. ...
- Javascript: 动态显示进度条
{% if not config.exec_id == '' %} <br /> <div class="progress"> <div class= ...
- scp: useful commands
Examples Copy the file "foobar.txt" from a remote host to the local host $ scp your_userna ...
- 【CV知识学习】【转】beyond Bags of features for rec scenen categories。基于词袋模型改进的自然场景识别方法
原博文地址:http://www.cnblogs.com/nobadfish/articles/5244637.html 原论文名叫Byeond bags of features:Spatial Py ...
- HDU 5305 Friends(简单DFS)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- Hadoop的学习前奏(二)——Hadoop集群的配置
前言: Hadoop集群的配置即全然分布式Hadoop配置. 笔者的环境: Linux: CentOS 6.6(Final) x64 JDK: java version "1.7 ...
- 通达OA 小飞鱼老师OA工作流设计课程教学网络公开课之HTML基础(一)
通达OA网络教学公开课開始了.有须要的小伙伴们抓住机会奥. 8月29号晚8点不见不散.本次课程的主要内容是通达OA工作流设计课程中须要用到的Html部分学习. 帮忙转发的朋友加送一节VIP课程.