var sparklineOptions = { height: 80,//Height of the chart - Defaults to 'auto' (line height of the containing tag) chartRangeMin: -1, chartRangeMax: 1, type: 'bar', barSpacing: 0, barWidth: 2, barColor: '#00bf5f', negBarColor: '#f22929', zeroColor: '#ffff00', }; $.getJSON("/sentiment_analysis_getplotdata/", function(data) { //console.log(data); var all_data = []; var plot_data = []; var graph_avg = []; var array_provider = Object.keys(data); var dates_providers = Object.keys(data[array_provider[0]]); var dateStart = parseInt(dates_providers[0]); var oneHour = 60*60; var oneWeek = oneHour*24*7; var all_graph_day_sum = 0.0; var all_graph_hour_sum = 0.0; for (graphNum=0; graphNum<8; graphNum++) { var max_value = 0.0; var graph_data = []; var spark_data = []; var curr_provider = array_provider[graphNum]; var curr_sum = 0.0; var day_sum = 0.0; var hour_sum = 0.0; for(curr_date=dateStart; curr_date max_value ? Math.abs(pos-neg) : max_value; if(curr_date >= dateStart+oneWeek-24*oneHour){ day_sum += (pos-neg); } if(curr_date >= dateStart+oneWeek-oneHour){ hour_sum += (pos-neg); } } } all_graph_day_sum += day_sum; all_graph_hour_sum += hour_sum; var curr_avg = curr_sum / (oneWeek/oneHour); //var curr_avg = curr_sum / (spark_data.length); graph_avg.push([curr_provider, curr_avg]); plot_data.push(spark_data); all_data.push(graph_data); sparklineOptions.chartRangeMax = max_value; sparklineOptions.chartRangeMin = -max_value; // print week var num = graphNum + 1; var placeholder = '.sparkLineStatsWeek' + num; $(placeholder).sparkline(plot_data[graphNum], sparklineOptions); $(placeholder+'t').text(curr_provider); $(placeholder+'s').text(curr_avg.toFixed(5)); sparklineOptions.barWidth = 7; $(placeholder+'b').sparkline([curr_avg], sparklineOptions); sparklineOptions.barWidth = 2; // print today var data_length = plot_data[graphNum].length; var data_today = plot_data[graphNum].slice(data_length-24*2, data_length-24*1); placeholder = '.sparkLineStatsToday' + num; sparklineOptions.barWidth = 14; $(placeholder).sparkline(data_today, sparklineOptions); $(placeholder+'t').text(curr_provider); sparklineOptions.barWidth = 7; $(placeholder+'b').sparkline([day_sum/24], sparklineOptions); sparklineOptions.barWidth = 2; }//for loop /* ---------------- Gauge ---------------- */ var gaugeOptions = { animateEasing: true, elementWidth: 200, elementHeight: 125, arcFillStart: 10, arcFillEnd: 12, arcFillTotal: 20, incTot: 1.0, arcBgColorLight: 200, arcBgColorSat: 0, arcStrokeFg: 20, arcStrokeBg: 30, colorArcFg: '#FF3300', animateSpeed: 1, }; // Clone object var gaugeOptions2 = jQuery.extend(true, {}, gaugeOptions); var gaugeOptions3 = jQuery.extend(true, {}, gaugeOptions); gaugeOptions.appendTo = '#gauge_today_last_hour'; gaugeOptions.dialLabel = 'Last hour'; gaugeOptions.elementId = 'gauge1'; gaugeOptions.inc = all_graph_hour_sum / 8; var gauge_today_last_hour = new FlexGauge(gaugeOptions); gaugeOptions2.appendTo = '#gauge_today_last_days'; gaugeOptions2.dialLabel = 'Today'; gaugeOptions2.elementId = 'gauge2'; gaugeOptions2.inc = all_graph_day_sum / 8; var gauge_today_last_days = new FlexGauge(gaugeOptions2); gaugeOptions3.appendTo = '#gauge_week'; gaugeOptions3.dialLabel = 'Week'; gaugeOptions3.elementId = 'gauge3'; var graph_avg_sum = 0.0; for (i=0; i= 24){ comp_sum_hour_pos += gauge_data[i].compoundPos; comp_sum_hour_neg += gauge_data[i].compoundNeg; } } var options_canvasJS_1 = { animationEnabled: true, axisY: { tickThickness: 0, lineThickness: 0, valueFormatString: " ", gridThickness: 0 }, axisX: { tickThickness: 0, lineThickness: 0, labelFontSize: 0.1, }, data: [ { type: "bar", color: "green", dataPoints: [ {y: comp_sum_hour_pos/8} ] }, { type: "bar", color: "red", dataPoints: [ {y: comp_sum_hour_neg/8} ] } ] }; var chart_canvas1 = new CanvasJS.Chart("bar_today_last_hour", options_canvasJS_1); var options_canvasJS_2 = { animationEnabled: true, axisY: { tickThickness: 0, lineThickness: 0, valueFormatString: " ", gridThickness: 0 }, axisX: { tickThickness: 0, lineThickness: 0, labelFontSize: 0.1, }, data: [ { type: "bar", color: "green", dataPoints: [ {y: comp_sum_day_pos/8} ] }, { type: "bar", color: "red", dataPoints: [ {y: comp_sum_day_neg/8} ] } ] }; var chart_canvas2 = new CanvasJS.Chart("bar_today_last_days", options_canvasJS_2); chart_canvas1.render(); chart_canvas2.render(); } );