charisma-master中绘points图时遇到问题及解决方法

1、在项目中使用动态数据代码如下:

<div class="box col-md-12">
    <div class="box-inner">
        <div class="box-header well">
            <h2><i class="glyphicon glyphicon-list-alt"></i> ***曲线</h2>

            <div class="box-icon">
                <a href="#" class="btn btn-minimize btn-round btn-default"><i
                        class="glyphicon glyphicon-chevron-up"></i></a>
            </div>
        </div>
        <div class="box-content">
            <div id="portchart" class="center" style="height:300px"></div>
            <p id="hoverdata">鼠标位置在 (<span id="x">0</span>, <span id="y">0</span>). <span id="clickdata"></span></p>
        </div>
    </div>
</div>

<script type="text/javascript">
$().ready(function(){
	var profits = [];
	var minVal = 0;
	var maxVal = 0;
	<span style="color:#ff0000;">var minStart = "";
	
	<c:forEach var="contract" items="${portreturnlist}" varStatus="state">
		<c:if test="${state.index == 0}">
			minStart = ${contract.workDate} + "";
			minStart = minStart.substr(0, 4) + "-" + minStart.substr(4, 2) + "-" + minStart.substr(6, 2);
		</c:if>
		profits.push([${state.index}, ${contract.returnRate}]);
		if(minVal > ${contract.returnRate}) minVal = ${contract.returnRate};
		if(maxVal < ${contract.returnRate}) maxVal = ${contract.returnRate};
	</c:forEach></span>

	var plot = $.plot($("#portchart"),
	    [
	        { data: profits, label: "***" }
	    ], {
	        series: {
	            lines: { show: true  },
	            points: { show: true }
	        },
	        grid: { hoverable: true, clickable: true, backgroundColor: { colors: ["#fff", "#eee"] } },
	        xaxis: {
	            ticks: [
				<span style="color:#ff0000;"><c:forEach var="contract" items="${portreturnlist}" varStatus="state" <strong>--step--</strong>>
				<span style="white-space:pre">	</span>[${state.index}, ${contract.workDate}],
				</c:forEach></span>
	                    ]
	        },
	        yaxis: { min: minVal - 1, max: maxVal + 1 },
	        colors: ["#539F2E", "#3C67A5"]
	    });
	
	function showTooltip(x, y, contents) {
	    $('<div id="tooltip">' + contents + '</div>').css({
	        position: 'absolute',
	        display: 'none',
	        top: y + 5,
	        left: x + 5,
	        border: '1px solid #fdd',
	        padding: '2px',
	        'background-color': '#dfeffc',
	        opacity: 0.80
	    }).appendTo("body").fadeIn(200);
	}
	
	var previousPoint = null;
	$("#portchart").bind("plothover", function (event, pos, item) {
	    $("#x").text(pos.x.toFixed(3));
	    $("#y").text(pos.y.toFixed(2));
	
	    if (item) {
	        if (previousPoint != item.dataIndex) {
	            previousPoint = item.dataIndex;
	
	            $("#tooltip").remove();
	            var x = item.datapoint[0],
	                y = item.datapoint[1].toFixed(2);
		    <span style="color:#ff0000;">var xStr = addDaysForNum(x);</span>
	            showTooltip(item.pageX, item.pageY, item.series.label + " 【" + xStr + " : " + y + "】");
	        }
	    }
	    else {
	        $("#tooltip").remove();
	        previousPoint = null;
	    }
	});
		
	$("#portchart").bind("plotclick", function (event, pos, item) {
	    if (item) {
	        $("#clickdata").text("您点击的点 " + item.dataIndex + " 在 " + item.series.label + ".");
	        plot.highlight(item.series, item.datapoint);
	    }
	});
	
<span style="background-color: rgb(204, 255, 255);">	<span style="color:#ff0000;">function addDaysForNum(days){
		var nd = new Date(minStart);
		nd = nd.valueOf();
		nd = nd + days * 24 * 60 * 60 * 1000;
		nd = new Date(nd);
		var y = nd.getFullYear();
		var m = nd.getMonth()+1;
		var d = nd.getDate();
		if(m <= 9) m = "0"+m;
		if(d <= 9) d = "0"+d; 
		return y + "" + m + "" + d;
	}</span></span>
});
</script>

2、红色的部分是我改造过的地方,其中前两个部分动态数据,第二部分中 --step-- 可以添加步长使横坐标表示更多的数据;

3、因为我的横坐标是日期,所以这里添加了横坐标日期的显示和处理;

charisma国外后台模版 # Charisma ### Free, premium quality, responsive, multiple skin admin template. ##[Live Demo](http://usman.it/themes/charisma/) ### [Download](https://github.com/usmanhalalit/charisma/archive/master.zip) ##Features - 9 different themes. - Fully responsive, optimized UI for tablets and mobile phones, [see how it looks on different devices](http://www.responsinator.com/?url=usman.it%2Fthemes%2Fcharisma). - Based on Bootstrap. - Works on IE9+ - Commented code. - Custom product tour, [see example](http://usman.it/themes/charisma/tour.html). - Grid system, [see example](http://usman.it/themes/charisma/grid.html). - Charts, including, pie, stack, flot, realtime etc. - Data tables - Widget boxes, collapsible, closable, [see example](http://usman.it/themes/charisma/grid.html). - Photo gallery [see example](http://usman.it/themes/charisma/gallery.html). - Ajaxified menus - Full calendar, monthly weekly, daily, with todo list. - Custom error page - Auto active link detection and much more. ## Credits Without these open osurce software Charisma woudn't have been possible: - [Twitter Bootstrap](http://getbootstrap.com/) - [jQuery](http://jquery.com) - [Bootswatch](http://bootswatch.com/) - [Chsoen](http://harvesthq.github.com/chosen/) - [Flot Charts](http://www.flotcharts.org/) - [Full Calendar](http://arshaw.com/fullcalendar/) - [Datatables](http://datatables.net/) - [Colorbox](http://www.jacklmoore.com/colorbox/) - [Noty](http://ned.im/noty/) - [Raty](http://wbotelhos.com/raty) - iPhone-style Checkboxes - [Autogrowing Textarea](http://onehackoranother.com/projects/jquery/jquery-grab-bag/autogrow-textarea.html) - [Animate.css](http://daneden.github.io/animate.css/) - [Uploadify](http://www.uploadify.com/) Please visit [http://usman.it/free-responsive-admin-template/](http://usman.it/free-responsive-admin-template/ "") for more information. ### [Donate Charisma](http://flattr.com/thing/1507720/usmanhalalitcharisma-on-GitHub) ___ © 2012 - 2014 [Muhammad Usman](http://usman.it/). Licensed under the Apache License, Version 2.0.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值