这是我的代码:
<script>
function str_pad(i,l,s) {
var o = i.toString();
if (!s) { s = '0'; }
while (o.length < l) {
o = s + o;
}
return o;
}
function secondsToTime(secs)
{
var timeToNow = secs;
var onehour =3600;
var hours = timeToNow / onehour;
hours = Math.floor(hours);
var selisih =Math.abs(timeToNow - (hours * onehour));
timeToNow = selisih;
var minutes = timeToNow/60;
minutes = Math.floor(minutes);
selisih = Math.abs(timeToNow - (minutes * 60));
var second = Math.round(selisih);
var result = str_pad(hours,2) + ':' + str_pad(minutes,2)+ ':'+str_pad(second,2);
return result;
}
$(function () {
$(document).ready(function () {
$('#chartdiv').highcharts({
chart: {
zoomType: 'xy'
},
title: {
text: 'CS Performance Email Agent'
},
subtitle: {
text: ''
},
xAxis: [{
categories:[
<?php
for ($i=0; $i <2 ; $i++) {
?>
<?php echo "day - ".$i;?>,
<?php } ?>
],
crosshair: true
}],
yAxis: [{ // Primary yAxis
// type: 'datetime', //y-axis will be in milliseconds
// gridLineWidth: 1,
// dateTimeLabelFormats: { //force all formats to be hour:minute:second
// second: '%H:%M:%S',
// minute: '%H:%M:%S',
// hour: '%H:%M:%S',
// day: '%H:%M:%S',
// week: '%H:%M:%S',
// month: '%H:%M:%S',
// year: '%H:%M:%S'
// },
// // min: Math.min.apply(null, queueNumberArray),
// title: {
// text: ' Grand Average Time'
// }
labels: {
format: '{value}',
style: {
color: Highcharts.getOptions().colors[1]
}
},
title: {
text: 'Grand Total Average Time',
style: {
color: Highcharts.getOptions().colors[1]
}
}
}, { // Secondary yAxis
title: {
text: 'Grand Total',
style: {
color: Highcharts.getOptions().colors[0]
}
},
labels: {
format: '{value} ',
style: {
color: Highcharts.getOptions().colors[0]
}
},
opposite: true
}],
tooltip: {
formatter: function () {
var s = '<b>' + this.x + '</b>';
$.each(this.points, function () {
if (this.series.name=='Grand Total'){
s += '<br/>' + this.series.name + ' = ' +
this.y ;
}else{
s += '<br/>' + this.series.name + ' = ' +
secondsToTime(this.y) ;
}
});
return s;
},
shared:true,
},
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 100,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
},
series: [{
name: 'Grand Total',
type: 'column',
yAxis: 1,
data: [
<?php
$array_totals= (2,5,6);
for ($i=0; $i <2 ; $i++) {
?>
<?php echo $array_totals[$i] ?>,
<?php }?>
],
tooltip: {
valueSuffix: ' '
}
}, {
name: 'Grand Average Time',
type: 'spline',
data: [
<?php
$array_seconds= (26321.87, 13243.32, 334213.12);
for ($i=0; $i <2 ; $i++) {
?>
<?php
echo $array_seconds[$i];
?>,
<?php }?>
],
tooltip: {
},
}]
});
});
});
</script>