Ero sivun ”Widget:JwObsCharts” versioiden välillä
Järvi-meriwikistä
Rivi 792: | Rivi 792: | ||
//memo.axisMaxDate.setMonth( memo.axisMaxDate.getMonth()+1 ); | //memo.axisMaxDate.setMonth( memo.axisMaxDate.getMonth()+1 ); | ||
memo.axisMaxDate.setDate(31); | memo.axisMaxDate.setDate(31); | ||
− | + | console.log( memo.obsesA ); | |
− | |||
− | |||
− | |||
for (var o in memo.obsesA) { | for (var o in memo.obsesA) { | ||
− | + | obs = memo.obsesA[ o ]; | |
− | if (typeof memo. | + | s = obs.seriesId; |
− | memo. | + | if (typeof memo.seriesO[s] == 'undefined' ) { |
+ | memo.seriesO[ s ] = { 'id': s, 'order': parseInt( obs.data.cat ), 'title': i18n[ s ].title[ memo.lang ], 'type': 'scatter', 'color': i18n[ s ].color, 'obses': [] }; | ||
+ | } | ||
+ | obs.xvalue = obs.compareDate; | ||
+ | obs.yvalue = obs.value; | ||
+ | //obs.value = obs.obsdatetime.toLocaleDateString( memo.lang ); | ||
+ | obs.valueUnit = i18n[ 'Date' ][ memo.lang ]; | ||
+ | obs.tooltip = '<p><b>' + obs.season + '</b></p>'; | ||
+ | obs.tooltip += '<p>' + i18n[ s ].title2[ memo.lang ] + ': ' + obs.obsdatetime.toLocaleDateString( memo.lang ) + '</p>'; | ||
+ | obs.tooltip += obs.addInfo; | ||
+ | memo.seriesO[ s ].obses.push( obs ); | ||
} | } | ||
− | + | ||
− | for (var | + | memo.seriesA = []; for ( var s in memo.seriesO ) { memo.seriesA.push( memo.seriesO[s] ) }; |
+ | memo.seriesA.sort( function( a, b ) { return a.order-b.order; } ); | ||
+ | |||
+ | for ( var s in memo.seriesA ) { | ||
+ | if ( memo.seriesA[ s ].type == 'scatter' ) { | ||
+ | |||
+ | memo.data.addColumn( 'date', memo.seriesA[ s ].title ); // + ' ' + memo.obsMinYear + '-' + memo.obsMaxYear ); | ||
+ | memo.data.addColumn( { type: 'string', 'role': 'style' } ); | ||
+ | memo.data.addColumn( { type: 'string', role: 'tooltip', 'p': { 'html': true } } ); | ||
+ | memo.data.addColumn( { type: 'string', role: 'annotation' } ); | ||
+ | |||
+ | memo.options.series.push( { type: 'scatter', pointType: 'circle', pointSize: 9, color: memo.seriesA[ s ].color } ); | ||
+ | |||
+ | if ( memo.seriesA[ s ].obses.length > 1 ) { | ||
+ | memo.options.trendlines[ memo.options.series.length - 1 ] = { type: 'linear', title: i18n.trendline, lineWidth: 2.33, visibleInLegend: false, tooltip: false }; | ||
+ | } else { | ||
+ | memo.options.trendlines[ memo.options.series.length - 1 ] = { type: 'linear', title: i18n.trendline, lineWidth: 0, color: 'transparent', visibleInLegend: false, tooltip: false }; | ||
+ | } | ||
+ | } | ||
− | + | } | |
+ | // add data to table | ||
+ | cc = memo.data.getNumberOfColumns(); | ||
+ | var st = 0; | ||
+ | for ( var s in memo.seriesA ) { | ||
+ | |||
+ | for ( var o in memo.seriesA[ s ].obses ) { | ||
+ | |||
+ | obs = memo.seriesA[ s ].obses[ o ]; | ||
+ | |||
+ | dataRow = []; | ||
+ | |||
+ | // fill row with nulls | ||
+ | for ( var i=0; i<cc; i++ ) { dataRow.push( null ); } | ||
+ | |||
+ | // x axis value | ||
+ | dataRow[ 0 ] = obs.xvalue; | ||
+ | |||
+ | if ( memo.seriesA[ s ].type == 'candlestick' ) { | ||
+ | |||
+ | dataRow[ st+1 ] = obs.low; | ||
+ | dataRow[ st+2 ] = obs.low; | ||
+ | dataRow[ st+3 ] = obs.high; | ||
+ | dataRow[ st+4 ] = obs.high; | ||
+ | dataRow[ st+5 ] = obs.tooltip; | ||
+ | |||
+ | } else if ( memo.seriesA[ s ].type == 'scatter' ) { | ||
+ | |||
+ | dataRow[ st+1 ] = obs.yvalue; | ||
+ | dataRow[ st+2 ] = obs.style; | ||
+ | dataRow[ st+3 ] = obs.tooltip; | ||
+ | dataRow[ st+4 ] = null; | ||
+ | } | ||
+ | |||
+ | memo.dataA.push( dataRow ); | ||
+ | |||
+ | } | ||
+ | |||
+ | if ( memo.seriesA[ s ].type == 'candlestick' ) { | ||
+ | st += 5; | ||
+ | } else if ( memo.seriesA[ s ].type == 'scatter' ) { | ||
+ | st += 4; | ||
+ | } | ||
+ | |||
+ | } | ||
} | } | ||