Ero sivun ”Widget:XJwCharts” versioiden välillä
Järvi-meriwikistä
Rivi 6: | Rivi 6: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
− | + | ||
google.charts.load( 'current', { 'packages':[ 'corechart' ] } ); | google.charts.load( 'current', { 'packages':[ 'corechart' ] } ); | ||
google.charts.setOnLoadCallback( checkforjqready ); | google.charts.setOnLoadCallback( checkforjqready ); | ||
Rivi 19: | Rivi 19: | ||
function readytogo() { | function readytogo() { | ||
− | + | ||
+ | var now = new Date(); | ||
+ | |||
var jw = new jwApi(); | var jw = new jwApi(); | ||
Rivi 27: | Rivi 29: | ||
var data = {}; | var data = {}; | ||
− | var firstW = 3000; lastW = 0; | + | var firstW = 3000; lastW = 0; |
for ( var o in jw.obsList ) { | for ( var o in jw.obsList ) { | ||
Rivi 36: | Rivi 38: | ||
var winter = obs.obsdatetime.getFullYear(); | var winter = obs.obsdatetime.getFullYear(); | ||
if ( obs.obsdatetime.getMonth() > -1 && obs.obsdatetime.getMonth() < 8 ) { winter--; }; | if ( obs.obsdatetime.getMonth() > -1 && obs.obsdatetime.getMonth() < 8 ) { winter--; }; | ||
+ | |||
+ | var cdate = new Date( now.getFullYear(), obs.obsdatetime.getMonth(), obs.obsdatetime.getDate() ); | ||
+ | var days = ( cdate.getTime() - now.getTime() ) / ( 1000*60*60*24 ) ); | ||
firstW = Math.min( firstW, winter ); lastW = Math.min( lastW, winter ); | firstW = Math.min( firstW, winter ); lastW = Math.min( lastW, winter ); | ||
Rivi 42: | Rivi 47: | ||
if ( obs.data.cat == 2 ) { | if ( obs.data.cat == 2 ) { | ||
− | data[ winter ].freeze = | + | data[ winter ].freeze = days ); |
} else if ( obs.data.cat == 5 ) { | } else if ( obs.data.cat == 5 ) { | ||
− | data[ winter ].breakup = | + | data[ winter ].breakup = days ); |
} | } | ||
Rivi 68: | Rivi 73: | ||
console.log( data[o].breakup); | console.log( data[o].breakup); | ||
− | var row = [ o, data[o].freeze | + | var row = [ o, data[o].freeze, data[o].freeze, data[o].breakup, data[o].breakup ]; |
table.push( row ); | table.push( row ); | ||