這篇文章主要介紹了jQuery Chart圖表制作組件Highcharts用法,詳細(xì)分析了Highcharts插件的功能與具體使用技巧及相關(guān)注意事項(xiàng),需要的朋友可以參考下
本文實(shí)例講述了jQuery Chart圖表制作組件Highcharts用法。分享給大家供大家參考,具體如下:
Highcharts是一個(gè)制作圖表的純Javascript類庫(kù),主要特性如下:
① 兼容性:兼容當(dāng)今所有的瀏覽器,包括iPhone、IE和火狐等等;
② 對(duì)個(gè)人用戶完全免費(fèi);
③ 純JS,無BS;
④ 支持大部分的圖表類型:直線圖,曲線圖、區(qū)域圖、區(qū)域曲線圖、柱狀圖、餅裝圖、散布圖;
⑤ 跨語言:不管是PHP、Asp.net還是Java都可以使用,它只需要三個(gè)文件:一個(gè)是Highcharts的核心文件highcharts.js,還有a canvas emulator for IE和Jquery類庫(kù)或者M(jìn)ooTools類庫(kù);
⑥ 提示功能:鼠標(biāo)移動(dòng)到圖表的某一點(diǎn)上有提示信息;
⑦ 放大功能:選中圖表部分放大,近距離觀察圖表;
⑧ 易用性:無需要特殊的開發(fā)技能,只需要設(shè)置一下選項(xiàng)就可以制作適合自己的圖表;
⑨ 時(shí)間軸:可以精確到毫秒
下載插件
Highcharts下載地址
http://www.highcharts.com/download
jquery下載地址
http://jquery.com/
本次介紹是把highcharts中的第一個(gè)文件拷貝過來,然后把其他的功能加在了這個(gè)文件中,然后查詢相關(guān)資料,導(dǎo)出圖片格式不需要連到官方服務(wù)器了,只需要在本地就可以。
代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="highchart_export_module_asp_net._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Highchart js export module sample</title>
<!-- 1.引入jquery庫(kù) -->
<script src="Javascript/jquery-1.5.1.js" type="text/javascript"></script>
<!-- 2.引入highcharts的核心文件 -->
<script src="http://highcharts.com/js/highcharts.js" type="text/javascript"></script>
<!-- 3.引入導(dǎo)出需要的js庫(kù)文件 -->
<script src="http://highcharts.com/js/modules/exporting.js" type="text/javascript"></script>
</head>
<script language="javascript" type="text/javascript">
var chart;
$(document).ready(function () {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'line', //圖表類別,可取值有:line、spline、area、areaspline、bar、column等
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Monthly Average Temperature', //設(shè)置一級(jí)標(biāo)題
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com', //設(shè)置二級(jí)標(biāo)題
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']//設(shè)置x軸的標(biāo)題
},
yAxis: {
title: {
text: 'Temperature (°C)' //設(shè)置y軸的標(biāo)題
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
this.x + ': ' + this.y + '°C'; //鼠標(biāo)放在數(shù)據(jù)點(diǎn)的顯示信息,但是當(dāng)設(shè)置顯示了每個(gè)節(jié)點(diǎn)的數(shù)據(jù)項(xiàng)的值時(shí)就不會(huì)再有這個(gè)顯示信息
}
},
legend: {
layout: 'vertical',
align: 'right', //設(shè)置說明文字的文字 left/right/top/
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
exporting: {
enabled: true, //用來設(shè)置是否顯示‘打印','導(dǎo)出'等功能按鈕,不設(shè)置時(shí)默認(rèn)為顯示
url: "http://localhost:49394/highcharts_export.aspx" //導(dǎo)出圖片的URL,默認(rèn)導(dǎo)出是需要連到官方網(wǎng)站去的哦
},
plotOptions: {
line: {
dataLabels: {
enabled: true //顯示每條曲線每個(gè)節(jié)點(diǎn)的數(shù)據(jù)項(xiàng)的值
},
enableMouseTracking: false
}
},
series: [{
name: 'Tokyo', //每條線的名稱
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]//每條線的數(shù)據(jù)
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
});
});
</script>
<body>
<form id="form1" runat="server">
<!--5.導(dǎo)入容器用于顯示圖表-->
<div id="container" style="width: 900px;">
</div>
</form>
</body>
</html>
導(dǎo)出的圖片格式
可以做到頁面展示和導(dǎo)出的圖片一致了。
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。