(function () { 'use strict'; angular .module('hyperion') .controller('system.LocationsController.index', ['$scope', '$http', '$location', '$timeout', '$sessionStorage', 'timerange', 'modalDialog', 'authService', 'sysClock', 'CONFIG', function($scope, $http, $location, $timeout, $sessionStorage, timerange, modalDialog, authService, sysClock, CONFIG){ // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } $scope.ismanager = $sessionStorage.currentUser.ismanager; $scope.isLoading = true; // show ajax loader var time = timerange.calc($sessionStorage.currentUser.timerange); $scope.$on('trUpdate', function(event, payload) { // time range update event console.log('trUpdate event: ' + $sessionStorage.currentUser.timerange); time = timerange.calc($sessionStorage.currentUser.timerange); load_data().catch(error => { console.warn(error); }); }); function load_data() { $scope.isLoading = true; // show ajax loader let time_start = moment(time.start).format('YYYY-MM-DDTHH:mm:ss'); let time_end = moment(time.today).format('YYYY-MM-DDTHH:mm:ss'); console.log('time_start: ' + time_start); console.log('time_end: ' + time_end); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'locations(time_start:"' + time_start + '", time_end:"' + time_end + '", timezone:"' + sysClock.getTimeZone() + '") { ' + 'id ' + 'name ' + 'created ' + 'location_floors_total ' + 'location_rooms_total ' + 'location_equipment_total ' + 'power_consumption ' + 'co2_emission ' + 'status ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.locations = response.data.data.locations; $scope.isLoading = false; // hide ajax loader console.log($scope.locations); },function(error) { // failure console.error(error); } ); }); } $timeout(function() { load_data(); }, 100); $scope.addLocation = function() { $location.path('/system/locations/add'); }; $scope.viewLocation = function(location_id) { $location.path('/system/locations/view/'+location_id); }; }]) .controller('system.LocationsController.edit', ['$scope', '$http', '$location', '$timeout', '$filter', '$sessionStorage', 'modalDialog', 'authService', 'CONFIG', '$stateParams' , function($scope, $http, $location, $timeout, $filter, $sessionStorage, modalDialog, authService, CONFIG, $stateParams){ // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } $scope.isLoading = true; $timeout(function() { if(!$sessionStorage.currentUser.ismanager) { $scope.accessdenied = true; } else { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'locations(id:"' + $stateParams.location_id + '", date_start:"' + moment().format('YYYYMMDD') + '", date_end:"' + moment().format('YYYYMMDD') + '") { ' + 'id ' + 'name ' + 'address_street1 ' + 'address_street2 ' + 'address_zipcode ' + 'address_state ' + 'address_city ' + 'address_country { ' + 'id ' + 'name ' + '} ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.location = response.data.data.locations[0]; console.log($scope.location); },function(error) { // failure console.error(error); } ); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_country { ' + 'id ' + 'name ' + 'full_name ' + 'code_iso_31661 ' + 'calling_code ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.countries = response.data.data.dictionary_country; },function(error) { // failure console.error(error); } ); }); } $scope.isLoading = false; // show ajax loader }, 100); $scope.selectAddressCountry = function(){ $scope.location.address_country_id = $scope.location.address_country.id; }; $scope.save = function() { console.log($scope.location); authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'locationupdate ( ' + 'location_id: "' + $stateParams.location_id + '", ' + 'name: "' + $scope.location.name + '", ' + 'address_street1: ' + ($scope.location.address_street1 !== null ? ('"' + $scope.location.address_street1 + '"') : null) + ', ' + 'address_street2: ' + ($scope.location.address_street2 !== null ? ('"' + $scope.location.address_street2 + '"') : null) + ', ' + 'address_city: ' + ($scope.location.address_city !== null ? ('"' + $scope.location.address_city + '"') : null) + ', ' + 'address_state: ' + ($scope.location.address_state !== null ? ('"' + $scope.location.address_state + '"') : null) + ', ' + 'address_zipcode: ' + ($scope.location.address_zipcode !== null ? ('"' + $scope.location.address_zipcode + '"') : null) + ', ' + 'address_country_id: ' + $scope.location.address_country.id + '){ id }' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); $location.path('/system/locations/view/' + $stateParams.location_id); },function(error) { // failure console.error(error); } ); }); }; $scope.cancel = function() { $location.path('/system/locations/view/' + $stateParams.location_id); }; }]) .controller('system.LocationsController.view', ['$scope', '$state', '$http', '$location', '$timeout', '$filter', '$sessionStorage', 'timerange', 'modalDialog', 'authService', 'CONFIG', '$stateParams', 'sysClock', 'wiz', function($scope, $state, $http, $location, $timeout, $filter, $sessionStorage, timerange, modalDialog, authService, CONFIG, $stateParams, sysClock, wiz){ // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } $scope.visible = { floors: true, // show floors view floors_data: false, // true if floors data available devices: false, // show devices view devices_data: false // true if devices data available }; $scope.toggleView = function() { if($scope.visible.floors) { $scope.visible.floors = false; $scope.visible.devices = true; } else { $scope.visible.floors = true; $scope.visible.devices = false; } }; $scope.ismanager = $sessionStorage.currentUser.ismanager; $scope.isLoading = true; // show ajax loader /////////////////////////////////////////////////////////////////////////////////////// var time = timerange.calc($sessionStorage.currentUser.timerange); $scope.$on('trUpdate', function(event, payload) { // time range update event console.log('trUpdate event: ' + $sessionStorage.currentUser.timerange); time = timerange.calc($sessionStorage.currentUser.timerange); load_data().catch(error => { console.warn(error); }); }); /////////////////////////////////////////////////////////////////////////////////////// $scope.$on('clockUpdate', function(event, payload) { // time range update event console.log('clockUpdate event: ' + sysClock.getTimeZone()); Highcharts.setOptions({ colors: ['#192a56', '#00b894', '#ff4757'], time: { timezone: sysClock.getTimeZone() } }); if($scope.chart_consumption_drilldown) { // if data is shown in hourly graph chart_consumption_load_hourly_data($scope.chart_consumption_drilldown_timestamp); } else { // if data is shown in daily graph chart_consumption_load_daily_data(); } }); /////////////////////////////////////////////////////////////////////////////////////// $scope.cost_explorer_enabled = false; $scope.location = {isvisible: false}; $scope.rooms = []; function load_data() { return new Promise((resolve, reject) => { $scope.chart_loading = true; // show ajax loader let time_start = moment(time.start).format('YYYY-MM-DDTHH:mm:ss'); let time_end = moment(time.today).format('YYYY-MM-DDTHH:mm:ss'); console.log('time_start: ' + time_start); console.log('time_end: ' + time_end); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'costlocationconfig(location_id: "' + $stateParams.location_id + '"){' + 'project { ' + 'cost { ' + 'enabled ' + '} ' + '} ' + 'enabled ' + '}' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); $scope.cost_explorer_enabled = Boolean(response.data.data.costlocationconfig.enabled)&&Boolean(response.data.data.costlocationconfig.project.cost.enabled); resolve(); },function(error) { // failure console.error(error); reject(); }); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'locations(id:"' + $stateParams.location_id + '", time_start:"' + time_start + '", time_end:"' + time_end + '", timezone:"' + sysClock.getTimeZone() + '") { ' + 'id ' + 'name ' + 'location_floors_total ' + 'location_floors_active ' + 'location_rooms_total ' + 'location_rooms_active ' + 'location_equipment_total ' + 'location_equipment_active ' + 'avg_mo_power_consumption ' + 'power_consumption ' + 'co2_emission ' + 'status ' + 'floors { ' + 'id ' + 'created ' + 'name ' + 'sqm ' + 'status ' + 'floor_rooms_total ' + 'floor_rooms_active ' + 'floor_equipment_total ' + 'floor_equipment_active ' + 'power_consumption ' + 'co2_emission ' + '} ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve if(response.data.data.locations.length) { $scope.location = response.data.data.locations[0]; console.log($scope.location); $scope.location.isvisible = true; $scope.floors = $scope.location.floors; console.log($scope.floors); if($scope.location.floors.length) { $scope.visible.floors_data = true; load_consumptionChart().then(() => { // create chart object resolve(null); }); } else { reject('no floors found'); } /* $scope.equipment = $scope.location.equipment; if($scope.location.equipment.length) { $scope.visible.devices_data = true; } else { reject('no location level equipment found'); } */ } else { // object not found console.warn('location object not found'); } const averages = averages_load_data(); $scope.isLoading = false; $scope.location.power_consumption = $scope.location.power_consumption?$scope.location.power_consumption:0; $scope.location.co2_emission = $scope.location.co2_emission?$scope.location.co2_emission:0; },function(error) { // failure $scope.location.isvisible = false; console.error(error); } ); }); }); } $timeout(function() { load_data().then(() => { // nothing }).catch(error => { console.warn(error); }); }, 100); $scope.showPowerChart = function() { $scope.isLoading = true; $scope.cost_bill_type = 'electric'; // default const averages = averages_load_data(); load_consumptionChart().then(() => { $scope.isLoading = false; }); }; $scope.cost_bill_type = 'electric'; // default $scope.showCostChart = function(type) { console.log('showCostChart: ', type); $scope.isLoading = true; type = type?type:'electric'; switch(type) { case 'electric': $scope.chart_consumption_title = 'LTM Utility Costs: Electric'; $scope.cost_bill_type = 'electric'; $scope.chart_cost_electric = true; $scope.chart_cost_water = false; $scope.chart_cost_ngas = false; break; case 'water': $scope.chart_consumption_title = 'LTM Utility Costs: Water'; $scope.cost_bill_type = 'water'; $scope.chart_cost_electric = false; $scope.chart_cost_water = true; $scope.chart_cost_ngas = false; break; case 'ngas': $scope.chart_consumption_title = 'LTM Utility Costs: Natural Gas'; $scope.cost_bill_type = 'naturalgas'; $scope.chart_cost_electric = false; $scope.chart_cost_water = false; $scope.chart_cost_ngas = true; break; } const averages = averages_load_data(); const chart = load_costChart(); Promise.all([ averages, chart ]); $scope.isLoading = false; }; const averages_load_data = () => { console.log('averages_load_data'); return new Promise((resolve) => { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'costaggregateslocation(location_id: "' + $stateParams.location_id + '", bill_type: "' + $scope.cost_bill_type + '"){' + 'type ' + 'avgmocostbase ' + 'avgmocostcurr ' + 'avgmosavings ' + 'avgmosavingsprc ' + 'lastmodate ' + 'lastmocostbase ' + 'lastmocostcurr ' + 'lastmosavings ' + 'lastmosavingsprc ' + '}' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); $scope.summary = response.data.data.costaggregateslocation; $scope.summary.lastmodate = moment($scope.summary.lastmodate).format('MMM YYYY') },function(error) { // failure console.error(error); }); }); }); }; $scope.locationLight = function() { modalDialog.showDialog({ 'template':'modal.lightsetings.html', 'controller':'modalLightController', 'entity': "LOCATION" }).then( // settings applied function(settings){ var change = { state: settings.state, brightness: settings.brightness, scene: settings.id }; authService.getJWTAuth().then(authHeader => { change.brightness = change.brightness?wiz.dimm2wiz(change.brightness):null; var request = {'query': 'mutation { ' + 'locationlightchange ( ' + 'company_id: "' + $scope.location.company.id + '", ' + 'location_id: "' + $stateParams.location_id + '", ' + (change.scene ? ('scene: ' + change.scene + ', ') : '') + (change.brightness ? ('brightness: ' + change.brightness + ', ') : '') + 'state: ' + change.state + ')' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve //$state.reload(); console.log('response: ', response.data.data.locationlightchange); },function(error) { // failure console.error(error); } ); }); } ) } $scope.editLocation = function() { $location.path('/system/locations/edit/' + $stateParams.location_id); } $scope.addDevice = function() { modalDialog.showDialog({ 'template':'modal.newdevice.html', 'controller':'modalNewDeviceController' }).then( // acknowledge function(newdevice){ if(newdevice!==null) { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'equipmentadd ( ' + 'company_id: "' + $scope.location.company.id + '", ' + 'location_id: "' + $stateParams.location_id + '", ' + 'floor_id: null, ' + 'room_id: null, ' + 'model_id: ' + newdevice.model_id + ', ' + 'name: "' + newdevice.name + '"' + ') { id }' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(){ // resolve $state.reload(); },function(error) { // failure console.error(error); } ); }); } } ) } $scope.removeLocation = function() { modalDialog.showDialog({ 'template':'modal.codeconfirmation.html', 'controller':'modalCodeConfirmationController', 'subtitle': "DELETING LOCATION", 'message': "PLEASE VALIDATE WITH CONFIRMATION CODE" }).then( // acknowledge function(confirmationcode){ if(confirmationcode!==null) { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'locationdelete ( ' + 'passcode: "' + confirmationcode + '", ' + 'location_id: "' + $stateParams.location_id + '", ' + ')' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $location.path('/system/locations'); },function(error) { // failure console.error(error); } ); }); } } ) } $scope.viewEquipment = function(equipment_id) { $location.path('/system/equipment/' + equipment_id); } $scope.viewFloor = function(room_id) { $location.path('/system/floors/' + room_id); } $scope.back = function() { $location.path('/system/resources'); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// // CHART: COMMON //////////////////////////////////////////////////////////////////////////////////////////////////////////// $scope.is_chart_consumption = false; $scope.is_chart_cost = false; let chart_object = null; // chart (consumption & cost) object $scope.chart_loading = true; // turn on and off AJAX loader and show graph const chart_clean = () => { // remove data servies (empty graph) while(chart_object.series.length) { chart_object.series[0].remove(); } }; Highcharts.setOptions({ colors: ['#192a56', '#00b894', '#ff4757'], time: { timezone: sysClock.getTimeZone() }, lang: { thousandsSep: ',' } }); Highcharts.dateFormats = { 'Z': () => { return moment.tz(sysClock.getTimeZone()).format('Z'); } }; //////////////////////////////////////////////////////////////////////////////////////////////////////////// // CHART: POWER CONSUMPTION //////////////////////////////////////////////////////////////////////////////////////////////////////////// $scope.chart_consumption_drilldown = false; // false: graph shows data aggregated to 1d, true: aggregation to 1h $scope.chart_consumption_drilldown_timestamp = null; // if 1h aggregation is shown then this variable holds information about which day $scope.chart_consumption_drillup = () => { // exit from drilldown (back to 1d aggregation) chart_consumption_load_daily_data(); } const chart_consumption_load_daily_data = () => { // prepare loading 1d aggregation data to graph $scope.chart_consumption_drilldown = false; // mark drolldown false $scope.chart_consumption_drilldown_timestamp = null; // remove drilldown timestamp chart_clean(); // remove data servies (empty graph) $scope.chart_consumption_title = 'Last ' + $sessionStorage.currentUser.timerange + ' Days Power Consumption'; // set graph title let tickInterval = 86400000; // 3600 * 24 * 1000 = 1 day (tickInterval = 1d in milliseconds) chart_object.xAxis.forEach((xaxis, i) => { // set graph X Axis (time:days) display range xaxis.options.tickInterval = tickInterval; xaxis.setExtremes(time.start, time.today, true); }) let time_start = moment.utc(time.start).format('YYYY-MM-DDTHH:mm:ss'); let time_end = moment.utc(time.today).format('YYYY-MM-DDTHH:mm:ss'); chart_consumption_add_power_daily(time_start, time_end); // execute data request and series prepare } const chart_consumption_load_hourly_data = (timestamp) => { // drilldown: 24h data $scope.chart_consumption_drilldown = true; // mark drolldown true $scope.chart_consumption_drilldown_timestamp = timestamp; // remember for which day we show drilldown chart_clean(); // remove data servies (empty graph) $scope.chart_consumption_title = moment.utc(timestamp).format('ll') + ' Power Consumption'; // set graph title let tickInterval = 3600000; // 3600 * 1000 = 1 hour chart_object.xAxis.forEach((xaxis, i) => { // set graph X Axis (time:hours) display range xaxis.options.tickInterval = tickInterval; xaxis.setExtremes(timestamp, (timestamp + (tickInterval * 23)), true); }); let time_start = moment.utc(timestamp).format('YYYY-MM-DDTHH:mm:ss'); let time_end = moment.utc(timestamp + (tickInterval * 24)).format('YYYY-MM-DDTHH:mm:ss'); chart_consumption_add_power_hourly(time_start, time_end); // execute data request and series prepare } const chart_consumption_add_power_daily = (time_start, time_end) => { let power_series = { name: "Energy Consumption", type: "column", marker: { symbol: 'circle' }, yAxis: 0, zIndex: 1, tooltip: { valueSuffix: 'kWh' }, color: '#51c4d3', data: [] }; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'power_daily(object:"' + $stateParams.location_id + '", time_start:"' + time_start + '", time_end:"' + time_end + '", timezone:"' + sysClock.getTimeZone() + '") { ' + 'step ' + 'epoch ' + 'p_avg ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( (response) => { // resolve response.data.data.power_daily.forEach(day => { power_series.data.push({ x: parseInt(day.epoch, 10), y: day.p_avg }); }); chart_object.addSeries(power_series); },(error) => { // failure console.error(error); } ); }); } const chart_consumption_add_power_hourly = (time_start, time_end) => { let power_series = { name: "Energy Consumption", type: "column", marker: { symbol: 'circle' }, yAxis: 0, zIndex: 1, tooltip: { xDateFormat: '%b %e, %Y %l %p %Z', valueSuffix: 'kWh' }, color: '#51c4d3', data: [], }; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'power_hourly(object:"' + $stateParams.location_id + '", time_start:"' + time_start + '", time_end:"' + time_end + '", timezone:"' + sysClock.getTimeZone() + '") { ' + 'step ' + 'epoch ' + 'p_avg ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( (response) => { // resolve response.data.data.power_hourly.forEach(hour => { power_series.data.push({ x: parseInt(hour.epoch, 10), y: hour.p_avg }); }); chart_object.addSeries(power_series); },(error) => { // failure console.error(error); } ); }); } function load_consumptionChart() { $scope.is_chart_consumption = true; $scope.is_chart_cost = false; return new Promise((resolve, reject) => { new Highcharts.Chart({ chart: { renderTo: 'dashboard_chart', height: 200, borderWidth: 0 }, time: { useUTC: true }, title: { text: null }, subtitle: { text: null }, exporting: { enabled: false }, credits: { enabled: false }, accessibility: { announceNewData: { enabled: true } }, xAxis: { type: 'datetime', tickInterval: 86400000, // 24 * 3600 * 1000 = 1 day }, yAxis: [{ // Power Consumption labels: { format: '{value}kWh', style: { color: Highcharts.getOptions().colors[0] } }, title: { text: 'Power Consumption', style: { color: Highcharts.getOptions().colors[0] } } }], tooltip: { xDateFormat: '%b %e, %Y', shared: true }, legend: { enabled: false }, plotOptions: { column: { stacking: 'normal', dataLabels: { enabled: false } }, series: { cursor: 'pointer', pointPadding: 0.01, groupPadding: 0.01, borderWidth: 0.01, shadow: false, dataLabels: { enabled: false }, marker: { enabled: false }, point: { events: { click: function() { //console.log('drilldown: ' + this.series.name + ' ['+this.x+'] -> ' + $scope.chart_consumption_drilldown); if(!$scope.chart_consumption_drilldown) { $scope.chart_consumption_drilldown = true; chart_consumption_load_hourly_data(this.x); } } } } } }, drilldown: { activeAxisLabelStyle: { cursor: 'default', color: '#3E576F', fontWeight: 'normal', textDecoration: 'none' }, activeDataLabelStyle: { cursor: 'default', color: '#3E576F', fontWeight: 'normal', textDecoration: 'none' } } }, function(chart){ chart_object = chart; chart_consumption_load_daily_data(); // dafault $scope.chart_loading = false; resolve(); }); }); }; //////////////////////////////////////////////////////////////////////////////////////////////////////////// // CHART: UTILITIES COST //////////////////////////////////////////////////////////////////////////////////////////////////////////// const chart_cost_load_data = () => { // prepare loading 1m aggregation data to graph console.log('chart_cost_load_data'); return new Promise((resolve) => { chart_clean(); // remove data servies (empty graph) Promise.all([ chart_load_monthly_data() ]); resolve(null); }); } const chart_load_monthly_data = () => { console.log('chart_load_monthly_data'); return new Promise((resolve) => { let series_baseline = { name: "Baseline Cost", type: "column", marker: { symbol: 'circle' }, yAxis: 0, zIndex: 1, tooltip: { valuePrefix: '$' }, color: '#ced4da', data: [] }; let series_current = { name: "Current Cost", type: "column", marker: { symbol: 'circle' }, yAxis: 0, zIndex: 2, tooltip: { valuePrefix: '$' }, color: '#0197fe', data: [] }; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'costlocationmonthly(location_id:"' + $stateParams.location_id + '", bill_type:"' + $scope.cost_bill_type + '") { ' + 'epoch ' + 'isbase ' + 'base ' + 'current ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( (response) => { // resolve response.data.data.costlocationmonthly.forEach(month => { if(month.isbase) { // baseline month series_baseline.data.push({ x: parseInt(month.epoch, 10), //y: (month.base?month.base:0) y: month.base }); } else { series_baseline.data.push({ x: parseInt(month.epoch, 10), //y: (month.base?month.base:0) y: month.base }); series_current.data.push({ x: parseInt(month.epoch, 10), //y: month.current?month.current:0) y: month.current }); } }); chart_object.addSeries(series_baseline); chart_object.addSeries(series_current); resolve(null); },(error) => { // failure console.error(error); } ); }); }); }; function load_costChart() { console.log('load_costChart'); $scope.is_chart_consumption = false; $scope.is_chart_cost = true; return new Promise((resolve, reject) => { new Highcharts.Chart({ chart: { renderTo: 'dashboard_chart', height: 200, minHeight: 200, borderWidth: 0, marginTop: 0, marginRight: 0, marginLeft: 0, marginBottom: 40, spacingLeft: 0, spacingRight: 0, spacingBottom: 0, spacingTop: 0, backgroundColor: 'transparent', plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, }, time: { useUTC: true }, title: { text: null }, subtitle: { text: null }, exporting: { enabled: false }, credits: { enabled: false }, legend: { enabled: false }, accessibility: { announceNewData: { enabled: true } }, xAxis: { type: 'datetime', tickLength: 0, lineWidth: 0, dateTimeLabelFormats: { month: '%b %Y', // Display month and year on the x-axis labels year: '%Y' } }, yAxis: [{ // Power Cost Actial title: { text: 'Cost', style: { color: Highcharts.getOptions().colors[0] } }, gridLineWidth: 0, min: 0, opposite: false }], tooltip: { xDateFormat: '%b %Y', // Format tooltip to show month and year shared: true, outside: true, useHTML: true, backgroundColor: '#fff', borderWidth: 0 }, plotOptions: { column: { stacking: null, pointPadding: 0.05, borderWidth: 0.05, dataLabels: { enabled: false } }, series: { cursor: 'pointer', pointPadding: 0.05, borderWidth: 0.05, borderWidth: 0.05, minPointLength: 3, shadow: false, dataLabels: { enabled: false }, marker: { enabled: false }, } }, series: [] }, (chart) => { chart_object = chart; chart_cost_load_data(); // dafault $scope.chart_loading = false; resolve(); }); }); }; }]); })();