app/assets/javascript/c80_estate/backend/admin/sevents.js in c80_estate-0.1.0.3 vs app/assets/javascript/c80_estate/backend/admin/sevents.js in c80_estate-0.1.0.4

- old
+ new

@@ -19,10 +19,11 @@ var $p_ecoef_mess; // здесь вешаем hint на подпись "эффективность" var $p_ecoef_comment; // здесь выводим комментарий var $div_area_text_stats; var $ul_props; var $div_graph; + var $div_graph_canvas; var fBuild = function () { // зафиксируем html элементы $main_content = $('#main_content'); @@ -49,10 +50,11 @@ $div_area_text_stats = $("<div id='text_stats'></div>"); $ul_props = $("<ul><li id='title'></li><li id='atype'></li><li id='born_date' class='hidden'></li><li id='busy_time'></li><li id='free_time'></li><li id='all_time'></li><li id='assigned_person_title'></li><li id='property_title'></li><li id='all_areas_count'></li><li id='free_areas_count'></li><li id='busy_areas_count'></li></ul>"); $div_area_text_stats.append($ul_props); $div_graph = $("<div id='graph'></div>"); + $div_graph_canvas = $("<canvas id='graph_canvas' height='50'></canvas>").appendTo($div_graph); $div_index_adds.append($div_ecoef); $div_index_adds.append($div_area_text_stats); $div_index_adds.append($div_graph); @@ -124,11 +126,11 @@ var fInit = function () { fBuild(); fRequest(); }; - var fDrawChart = function (data_array_rows) { + var fDrawChart_google = function (data_array_rows) { //data_array = [ // ['Director (Year)', 'Rotten Tomatoes', 'IMDB'], // ['Alfred Hitchcock (1935)', 8.4, 7.9], // ['Ralph Thomas (1959)', 6.9, 6.5], // ['Don Sharp (1978)', 6.5, 6.4], @@ -172,9 +174,133 @@ chart.draw(data, options); } $('#graph').css('opacity','1.0').css('display','block'); + }; + + var fDrawChart_chart_js = function (data) { + + if (data != undefined) { + var ctx = $("#graph_canvas"); + + var chartInstance = new Chart(ctx, { + type: 'bar', + data: { + labels: data["labels"], + datasets: [ + { + label: "График занята/свободна", + backgroundColor: [ + 'rgba(255, 99, 132, 0.2)', + 'rgba(54, 162, 235, 0.2)', + 'rgba(255, 206, 86, 0.2)', + 'rgba(75, 192, 192, 0.2)', + 'rgba(153, 102, 255, 0.2)', + 'rgba(255, 159, 64, 0.2)' + ], + borderColor: [ + 'rgba(255,99,132,1)', + 'rgba(54, 162, 235, 1)', + 'rgba(255, 206, 86, 1)', + 'rgba(75, 192, 192, 1)', + 'rgba(153, 102, 255, 1)', + 'rgba(255, 159, 64, 1)' + ], + borderWidth: 1, + barPercentage: 1.0, + categoryPercentage: 0, + data: data["points"] + } + ] + }, + options: { + scales: { + xAxes: [{ + type: 'time', + time: { + displayFormats: { + quarter: 'YYYY/MM/DD' + } + } + }] + } + } + }); + + $('#graph').css('opacity','1.0'); + + } + + }; + + var fDrawChart = function (data) { + if (data != undefined) { + + var dataPoints = []; + //[ + // {x: new Date(2012,0), y: 8.3} , + // {x: new Date(2012,1), y: 8.3} , + // {x: new Date(2012,2), y: 8.2} , + // {x: new Date(2012,3), y: 8.1} , + // {x: new Date(2012,4), y: 8.2} , + // {x: new Date(2012,5), y: 8.2} , + // {x: new Date(2012,6), y: 8.2} , + // {x: new Date(2012,7), y: 8.1} , + // {x: new Date(2012,8), y: 7.8} , + // {x: new Date(2012,9), y: 7.9} , + // {x: new Date(2012,10), y:7.8} , + // {x: new Date(2012,11), y:7.8} , + // {x: new Date(2013,0), y:7.9} , + // {x: new Date(2013,1), y:7.7} , + // {x: new Date(2013,2), y:7.6} , + // {x: new Date(2013,3), y:7.5} + //] + + var i, iob; + for (i = 0; i < data.length; i ++) { + iob = data[i]; + dataPoints.push({ + x: new Date(iob["year"], iob["month"], iob["day"]), + y: iob["val"] + }) + } + + var chart = new CanvasJS.Chart("graph", + { + title:{ + text: "График занята/свободна" + }, + animationEnabled: true, + axisY:{ + includeZero: false, + interval: 1, + valueFormatString: "" + }, + toolTip:{ + contentFormatter: function ( e ) { + var res = "Свободна"; + if (e.entries[0].dataPoint.y == 1) { + res = "Занята" + } + return res; + } + }, + data: [ + { + type: "stepLine", + //toolTipContent: "{x}: {y}%", + markerSize: 5, + dataPoints: dataPoints + } + + ] + }); + + $('#graph').css('opacity','1.0').css('display','block'); + chart.render(); + + } }; fInit(); }; \ No newline at end of file