window.addEventListener('load', function () { const ctx = document.getElementById('MEvsOSEBX').getContext('2d'); var MEvsOSEBX = false; draw_graph = function( response ){ const datapoints = JSON.parse( response.response ); const data = { labels: datapoints['labels'], datasets: [ { label: 'Dine tips', data: datapoints['user'], pointRadius: 1, borderColor: '#DD4800', fill: false, cubicInterpolationMode: 'monotone', tension: 1.4 }, { label: 'MarketExperts', data: datapoints['marketexperts'], pointRadius: 1, borderColor: '#0067AC', fill: false, cubicInterpolationMode: 'monotone', tension: 1.4 }, { label: 'OSEBX', data: datapoints['osebx'], pointRadius: 1, borderColor: '#006864', fill: false, cubicInterpolationMode: 'monotone', tension: 1.4 } ] }; const config = { type: 'line', data: data, options: { responsive: true, maintainAspectRatio: false, plugins: { title: { display: true, text: 'Akkumulert avkastning i MarketExperts-portefoljen vs OSEBX (hovedindeksen)' }, tooltip: { callbacks: { label: function( context ) { let label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.y !== null) { label += context.parsed.y + '%'; } return label; } } } }, interaction: { intersect: false, }, scales: { x: { display: true, title: { display: true } }, y: { display: true, ticks: { callback: function( value, index, values ){ return value +'%'; } }, title: { display: true, text: 'Avkastning' }, } } }, }; if ( MEvsOSEBX ){ MEvsOSEBX.destroy(); } MEvsOSEBX = new Chart(ctx, config ); } var url = 'https://my.marketexperts.info/_ajax'; var parameters = 'action=graph_users&graph_type=days'; ajax( url, parameters, draw_graph ); redraw_graph = function( type ){ var url = 'https://my.marketexperts.info/_ajax'; var parameters = 'action=graph_users&graph_type='+ type; ajax( url, parameters, draw_graph ); }; });