当前位置: 代码迷 >> Web前端 >> Highcharts作漂亮的曲线图
  详细解决方案

Highcharts作漂亮的曲线图

热度:285   发布时间:2012-09-23 10:28:11.0
Highcharts做漂亮的曲线图

var stockchart;
var curreychart;
$(document).ready(
		function() {
			$.getJSON("gotDailyReportStockView.statFund", function(data) {
				var stockoptions=createSeries('股票型日报统计图','净值(%)','净值','stockcontainer',data.stock);
				var curreyoptions=createSeries('货币型日报统计图','每万分已实现收益(%)','收益','currencycontainer',data.currency);
				stockchart = new Highcharts.Chart(stockoptions);
				curreychart=new Highcharts.Chart(curreyoptions);
			});
		});


function createSeries(title,text,toolTitle,rendercontainer,data){
	var options = {
			chart : {
				renderTo : rendercontainer,
				defaultSeriesType : 'spline'
			},
			title : {
				text : title,
				x : -20
			// center
			},
			xAxis : {
				type : 'datetime',
				tickInterval : 7 * 24 * 3600 * 1000, // one week
				categories : [],
				gridLineWidth : 1
			},
			yAxis : {
				title : {
					text : text
				}
			},
			legend : {
				enabled : true
			},
			exporting : {
				enabled : false
			},
			tooltip : {
				formatter : function() {
					return '<b>' + this.series.name + '</b><br/>'
							+ data["label"][this.x] + '  '+toolTitle+':' + this.y;
				}
			},
			plotOptions : {
				spline : {
					cursor : 'pointer',
					point : {
						events : {
							click : function() {
								hs.htmlExpand(null, {
									pageOrigin : {
										x : this.pageX,
										y : this.pageY
									},
									headingText : this.series.name,
									maincontentText : 'this.category: '
											+ this.category
											+ '<br/>this.y: ' + this.y,
									width : 200
								});
							}
						}
					}
				}
			},
			series : []
		}
	$.each(data, function(key, val) {
		if (key != 'label') {
			options.series.push( {
				name : key,
				data : val
			});
		}
	});
	return options
}

?categories :X坐标设置

?series:Y坐标设置.

?附件为API