Highcharts with all data for tooltip

本文展示了如何使用PHP生成JSON数据,并通过JavaScript进行数据处理和交互展示,包括时间戳转换、数据结构构建和JSON数据输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP code

	header("Content-type: text/json");

	$items = array();
        while($row = mysql_fetch_object($rs)){
		$newDT = strtotime($row->dt) * 1000;
		$pass_rate = $row->pass_rate;
		$items[$row->tester]['name']=$row->tester;
		$product = $row->product;
		$PSPT = $row->PSPT;
		$lot = $row->lot;
		$wafer = $row->wafer;
		$comment = $row->comment;			
		
		// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
		$x = strtotime($row->dt) * 1000;
		$y = floatval($row->pass_rate);	
		$ret = array($x, $y);
		
		$arrDetails = array('PSPT' => $PSPT, 'product' => $product, 'lot' => $lot, 'wafer' => $wafer, 'comment' => $comment );
		$items[$row->tester]['data'][]=json_encode($ret);
		$items[$row->tester]['details']["$x"]=json_encode($arrDetails);
	}
	print json_encode($items);

  Javascipt code:

var globalData = {}; //declare a json variable

$.getJSON('data_main.php', function(data) {					
	$.each(data, function(key,value) {
		globalData[key] = value; //update to globalData for tooltip
	});	
});	

formatter: function(){					
	var json = eval("("+globalData[this.series.name]["details"][this.x]+")");
	var tt = "<b>Tester: </b>"+this.series.name + "<br />";
	tt = tt+ "<b>PSPT: </b>"+json.PSPT + "<br />";
	tt = tt+ "<b>Product: </b>"+json.product + "<br />";
	tt = tt+ "<b>Lot: </b>"+json.lot + "<br />";
	tt = tt+ "<b>Wafer: </b>"+json.wafer + "<br />";
	tt = tt+ "<b>comment: </b>"+json.comment + "<br />";
	return tt;
}

  Result:

转载于:https://www.cnblogs.com/binglong/p/4512762.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值