/**
*制作 复杂的组合型的 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的更多相关文章

  1. Highcharts - Bar Chart & Column Chart

    1. 条形图(Bar Chart)需要的数据格式类型如下: ["Luke Skywalker", "Darth Vader", "Yoda" ...

  2. Highcharts - Pie Chart

    1. 饼状图(Pie Chart)示例: <div id="container" style="height: 400px"></div> ...

  3. 【HighCharts系列教程】三、图表属性——chart

    一.chart属性说明 Chart是HighCharts图表中主要属性,包括了图表区域的颜色.线条.高度.宽度.对齐.图表类型等诸多属性,也是HighCharts图表中必须配置的属性之一. 配置cha ...

  4. Highcharts 测量图;Highcharts 圆形进度条式测量图;Highcharts 时钟;Highcharts 双轴车速表;Highcharts 音量表(VU Meter)

    Highcharts 测量图 配置 chart.type 配置 配置 chart 的 type 为 'gauge' .chart.type 描述了图表类型.默认值为 "line". ...

  5. highcharts使用笔记

    1.legend取消点击事件: 饼图:plotOptions.pie.point.events.legendItemClick = function() {return false;} 其他,如:pl ...

  6. Highcharts指南

    摘要 Highcharts图表控件是目前使用最为广泛的图表控件.本文将从零开始逐步为你介绍Highcharts图表控件.通过本文,你将学会如何配置Highcharts以及动态生成Highchart图表 ...

  7. 相识Highcharts,几分钟玩转Highcharts

    Highcharts是一个功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯js图表库. 官网:http://www.hcharts.cn/ 我觉得对于刚接触一个东西的新手来说,有时候对一个东西真 ...

  8. Highcharts结合PhantomJS在服务端生成高质量的图表图片

    项目背景 最近忙着给部门开发一套交互式的报表系统,来替换原有的静态报表系统. 老系统是基于dotnetCHARTING开发的,dotnetCHARTING的优势是图表类型丰富,接口调用简单,使用时只需 ...

  9. highcharts图表中级入门之xAxis label:X(横)坐标刻度值过长截断多行(换行)显示问题说明

    在使用highcharts图表的过程中,总会碰到这样一个很是棘手的问题,横坐标刻度值太长,在不换行显示的情况下显得格外拥挤.虽然针对这一问题是可以对其刻度值进行旋转以此来避开显示拥挤问题[如何让hig ...

随机推荐

  1. 关于使用CELERY的一点心得

    使用也有大半年了.稳定性没话说啊. 但有一个坑,是我以前没注意的,记录下来. 就是本来一个任务是可以异步并行执行的..但如何需要CELERY的执行结果来作判断的话,就会变得异步串行的. 这要值得注意. ...

  2. [BZOJ1096][ZJOI2007]仓库建设(斜率优化DP)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1096 分析: 假设1~10,如果在3 6 10建立仓库,那么当前建立仓库决策下的最优值 ...

  3. Oops, 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine error

    环境: Win7 64位 + VS2005 + Office2013 64位 现象:程序为一个Excel导入程序,导入时报「'Microsoft.ACE.OLEDB.12.0' provider is ...

  4. PHP array_pad()

    定义和用法 array_pad() 函数向一个数组插入带有指定值的指定数量的元素. 语法 array_pad(array,size,value) 参数 描述 array 必需.规定数组. size 必 ...

  5. Java - this的使用方法

    this在内部获得当前对象的引用时调用: (1) return返回当前对象; (2) 构造器调用还有一个构造器, 带參数; (3) 參数的名称和数据成员的名称同样; 注意: this构造器在方法中仅仅 ...

  6. CocoaPods pod instal慢、卡住解决方法

    CocoaPods pod install慢.卡住解决方法 近期使用CocoaPods来加入第三方类库,不管是运行pod install还是pod update都卡在了Analyzing depend ...

  7. jQuery事件传播,事件流

    一. jQuery事件传播 在DOM2级事件模型中,一旦事件被触发.事件流首先从DOM树顶部(文档节点)向下传播.直到目标节点.然后再从目标节点向上传播到DOM树顶.从上到下的过程被称为捕获阶段.从下 ...

  8. WAMP 2.5 &quot;FORBIDDEN&quot; error

    对于web开发人员来说.远程訪问站点能够非常方便的提高开发站点开发效率,那么在wamp环境下,默认仅仅支持本地訪问,那么怎样訪问开启远程站点訪问呢? 开启方法: wamp2.5(32bit) 集成环境 ...

  9. mysql 多日志表结果集合拼接存储过程

    通常单天的日志 仅仅记录当天的日志信息,假设须要查看一月内的日志信息须要对每天的日志表结果集合进行拼接,通经常使用到 union . 储存过程: drop PROCEDURE if EXISTS un ...

  10. open_basedir restriction in effect,解决php引入文件权限问题 lnmp

    1.配置了虚拟域名 vim /usr/local/nginx/conf/vhost/siemens.conf server { listen 80; #listen [::]:80 default_s ...