只是简单是封装了一下,目前只能输出线图(折现,圆滑线等),柱状图。

代码如下:

;!function(win,$,AC,undefined){
var DDcharts = function(o){
this.o = $.extend(true,{},this.default_o,o);
if(this.o.type == 'serial'){
this.chart = this.AmSerialChart();
this.setCateGoryAxis().setValueAxis().setChartCursor().setAmLegend();
}
}; DDcharts.prototype = {
default_o:{
type:'serial', // 类型:折线、饼图等
dataProvider:{}, // 数据对象
categoryField:'date',
autoMargins:true,
marginTop:0,
marginRight:0,
marginBottom:0,
marginLeft:0,
startDuration:1, // 动画时间
write2where:'ddchart',
// 横轴
categoryAxis:{
parseDates:true,
minPeriod:'DD', // 最小时间:fff - milliseconds, ss - seconds, mm - minutes, hh - hours, DD - days, MM - months, YYYY - years.
inside:false,
fillAlpha:0.1, // 间隔区域透不明度
fillColor:'#cccccc', // 间隔区域填充颜色
labelRotation:0, // 刻度旋转角度
startOnAxis:0
},
// 纵轴
valueAxis:{
title:'', // 轴名称
axisAlpha:0,
dashLength:5
},
line:{
type:'line', // Possible values are: "line", "column", "step", "smoothedLine", "candlestick", "ohlc". XY and Radar charts can only display "line" type graphs.
valueField:'value',
hideBulletsCount:50
}
},
AmSerialChart:function(){
var chart = new AC.AmSerialChart();
chart.dataProvider = this.o.dataProvider;
chart.categoryField = this.o.categoryField;
chart.autoMargins = this.o.autoMargins;
chart.startDuration = this.o.startDuration;
if(this.o.autoMargins == false){
chart.marginTop= this.o.marginTop;
chart.marginRight= this.o.marginRight;
chart.marginBottom= this.o.marginBottom;
chart.marginLeft= this.o.marginLeft;
}
return chart;
},
// 设置横轴
setCateGoryAxis:function(){
var categoryAxis = this.chart.categoryAxis;
categoryAxis.parseDates = this.o.categoryAxis.parseDates; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = this.o.categoryAxis.minPeriod; // our data is daily, so we set minPeriod to DD
categoryAxis.inside = this.o.categoryAxis.inside;
categoryAxis.gridAlpha = 0; // 格子线不透明度 0 - 透明,1 - 不透明
categoryAxis.axisAlpha = 0; // 轴不透明度 0 - 透明,1 - 不透明
categoryAxis.fillAlpha = this.o.categoryAxis.fillAlpha;
categoryAxis.fillColor = this.o.categoryAxis.fillColor;
categoryAxis.labelRotation = this.o.categoryAxis.labelRotation;
categoryAxis.startOnAxis = this.o.categoryAxis.startOnAxis;
return this;
},
// 设置纵轴
setValueAxis:function(){
var valueAxis = new AC.ValueAxis();
valueAxis.axisAlpha = this.o.valueAxis.axisAlpha;
valueAxis.dashLength = this.o.valueAxis.dashLength;
valueAxis.title = this.o.valueAxis.title;
this.chart.addValueAxis(valueAxis);
return this;
},
// 添加鼠标滑过时的效果
setChartCursor:function(){
var chartCursor = new AC.ChartCursor();
this.chart.addChartCursor(chartCursor);
return this;
},
// LEGEND
setAmLegend:function(){
var legend = new AC.AmLegend();
legend.markerType = "square"; // Possible values are: "square", "circle", "line", "dashedLine", "triangleUp", "triangleDown", "bubble", "none".
this.chart.addLegend(legend);
},
// 增加折线
addLine:function(valueField,type,title){
var graph = new AC.AmGraph();
graph.type = type || this.o.line.type;
if(graph.type == 'column'){
graph.fillAlphas = 0.8;
}else{
graph.bullet = "round";
}
graph.valueField = valueField || this.o.line.valueField;
graph.title = title || graph.valueField;
graph.balloonText = "[[title]]: [[value]]";
graph.hideBulletsCount = this.o.line.hideBulletsCount; // this makes the chart to hide bullets when there are more than 50 series in selection
this.chart.addGraph(graph);
return this;
},
// 输出
write:function(write2where){
this.chart.write(write2where || this.o.write2where);
}
} win.DDcharts = DDcharts; }(this,jQuery,AmCharts);

使用实例(ddcharts.js为上述封装代码):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>amCharts examples</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script src="Public/js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="Public/js/amcharts.js" type="text/javascript"></script>
<script src="Public/js/ddcharts.js" type="text/javascript"></script>
<script type="text/javascript">
var lineChartData = [{
date: new Date(2009, 10, 2),
value: 5,
value1:6
}, {
date: new Date(2009, 10, 3),
value: 15,
value1:16
}, {
date: new Date(2009, 10, 4),
value: 13,
value1:6
}, {
date: new Date(2009, 10, 5),
value: 17,
value1:36
}, {
date: new Date(2009, 10, 6),
value: 15,
value1:6
}, {
date: new Date(2009, 10, 9),
value: 19,
value1:2
}, {
date: new Date(2009, 10, 10),
value: 21,
value1:6
}, {
date: new Date(2009, 10, 11),
value: 20,
value1:11
}, {
date: new Date(2009, 10, 12),
value: 20,
value1:18
}, {
date: new Date(2009, 10, 13),
value: 19,
value1:12
}, {
date: new Date(2009, 10, 16),
value: 25,
value1:17
}, {
date: new Date(2009, 10, 17),
value: 24,
value1:19
}, {
date: new Date(2009, 10, 18),
value: 26,
value1:6
}, {
date: new Date(2009, 10, 19),
value: 27,
value1:2
}, {
date: new Date(2009, 10, 20),
value: 25,
value1:6
}, {
date: new Date(2009, 10, 23),
value: 29,
value1:61
}, {
date: new Date(2009, 10, 24),
value: 28,
value1:16
}, {
date: new Date(2009, 10, 25),
value: 30,
value1:2
}, {
date: new Date(2009, 10, 26),
value: 72,
value1:6,
customBullet: "images/redstar.png" // note, one line has a custom bullet defined
},
{
date: new Date(2009, 10, 27),
value: 43,
value1:32
}, {
date: new Date(2009, 10, 30),
value: 31,
value1:16
}, {
date: new Date(2009, 11, 1),
value: 30,
value1:16
}, {
date: new Date(2009, 11, 2),
value: 29,
value1:6
}, {
date: new Date(2009, 11, 3),
value: 27,
value1:3
}, {
date: new Date(2009, 11, 4),
value: 26,
value1:45
}]; $(function(){
var ddcharts = new DDcharts({dataProvider:lineChartData,categoryAxis:{inside:false,labelRotation:0},line:{type:'smoothedLine'}});
ddcharts.addLine().addLine("value1",'line').write('chartdiv');
});
</script>
</head> <body>
<div id="chartdiv" style="width:100%; height:400px;"></div>
</body> </html>

amcharts简单封装的更多相关文章

  1. Android AsyncTask 深度理解、简单封装、任务队列分析、自定义线程池

    前言:由于最近在做SDK的功能,需要设计线程池.看了很多资料不知道从何开始着手,突然发现了AsyncTask有对线程池的封装,so,就拿它开刀,本文将从AsyncTask的基本用法,到简单的封装,再到 ...

  2. FMDB简单封装和使用

    工具:火狐浏览器+SQLite Manager插件 ; Xcode; FMDB库; 效果: 项目地址: https://github.com/sven713/PackFMDB 主要参考这两篇博客: 1 ...

  3. Android--Retrofit+RxJava的简单封装(三)

    1,继续接着上一篇的讲讲,话说如果像上一篇这样的话,那么我们每一次请求一个结构都要创建一堆的Retrofit对象,而且代码都是相同的,我们可以试试封装一下 先创建一个HttpMethods类,将Ret ...

  4. okhttp3 get post 简单封装

    最近打算在新项目中使用 okhttp3, 简单封装了一下异步 get post 因为 CallBack 也是在子线程中执行,所以用到了 Handler public class MyOkHttpCli ...

  5. python网页请求urllib2模块简单封装代码

    这篇文章主要分享一个python网页请求模块urllib2模块的简单封装代码. 原文转自:http://www.jbxue.com/article/16585.html 对python网页请求模块ur ...

  6. 对pymysql的简单封装

    #coding=utf-8 #!/usr/bin/python import pymysql class MYSQL: """ 对pymysql的简单封装 "& ...

  7. iOS开发——UI篇OC篇&UITableView简单封装

    UITableView简单封装 UITableView时iOS开发中使用最多也是最重的一个UI空间,其实在App Store里面的%80以上的应用都用到了这个控件,所以就给大家介绍一下,前面的文章中也 ...

  8. iOS sqlite 增删改查 简单封装(基于 FMDB)

    /** *  对 sqlite 的使用进行简单封装,仅涉及简单的单表 增删改查 * *  基于 FMDB * *  操作基于 model ,数据库表字段与 model 属性一一对应,对 model 整 ...

  9. ADO简单封装(MFC)

    简单封装了一下,不是很严谨. /************************************************************************/ /* INSTRUC ...

随机推荐

  1. 7.Knockout.Js(Mapping插件)

    前言 Knockout设计成允许你使用任何JavaScript对象作为view model.必须view model的一些属性是observable的,你可以使用KO绑定他们到你的UI元素上,当这些o ...

  2. ubuntu14.04字符界面中文乱码及中文输入

    作为ubuntu用户字符界面是绝对不陌生的,尤其是维护管理服务器的朋友为了节省资源都是用的字符界面,但是默认字符界面中文目录文件都是乱码,根本无法打开编辑,那么怎么让字符界面显示中文目录文件,还有在字 ...

  3. 37.altium designer中的class和rules?

    在布局布线工程中,遇到复杂工程时,难免要进行class和rules的设置,经过试验证明,class和rules的子目录是有优先级的.

  4. cnblogs体验

    用博客园可以让我更好的关注我们班同学的情况,通过关注他们,浏览他们发布的博客,学习到了很 多,比如不同的设计思想,良好的变成习惯,变量命名,缩进,注释等,而且自己不会的,可以帮助自己 有一些想法,是自 ...

  5. “我爱淘”冲刺阶段Scrum站立会议10

    完成任务: 完成了webservice的配置与测试,可以将数据库中的内容解析出来. 计划任务: 在客户端通过查询可以得到想要的书籍内容. 遇到问题: 客户端的内容获取还没有实现.

  6. Careercup - Google面试题 - 5085331422445568

    2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...

  7. python 网络编程-TCP/UDP

    摘抄自:廖雪峰的官方网站:http://www.liaoxuefeng.com/ TCP客户端和服务器端代码: #coding=utf-8 #客户端程序TCP 连接 import socket s=s ...

  8. .NET Framework 4.5、4.5.1 和 4.5.2 中的新增功能

    .NET Framework 4.5.4.5.1 和 4.5.2 中的新增功能 https://msdn.microsoft.com/zh-cn/library/ms171868.aspx

  9. 【CentOS】IBM X3650M4 IMM远程管理【转载】

    问题描述:          IBM X3650M4 IMM远程开机和关机   参考资料:             http://www.ibmsys.cn/blog/?p=201   问题解决: 一 ...

  10. 【BZOJ】【2938】【POI2000】病毒

    AC自动机 好题>_<(其实是一次AC有些感动) 嗯要找到无限长的一个字符串不包含任何一个模板串,就意味着在AC自动机(Trie图)上找到一个不经过任何一个危险结点的环,深搜一下就好了…… ...