Skip to content

Instantly share code, notes, and snippets.

@pdxwebdev
Created August 26, 2016 21:25
Show Gist options
  • Save pdxwebdev/dd439d4c63f8d28ee9f36a750e3a59eb to your computer and use it in GitHub Desktop.
Save pdxwebdev/dd439d4c63f8d28ee9f36a750e3a59eb to your computer and use it in GitHub Desktop.
angular.module('ChartCtrl', []).controller('ChartController', ['$scope', '$stateParams', '$element', '$http', function($scope, $stateParams, $element, $http) {
$http.get('/api/chart').then(function(res) {
var ctx = document.getElementById("skillsTrends");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: res.data.labels,
datasets: [
{
label: "# of Opportunities",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: res.data.data,
spanGaps: false,
}
]
}
});
$scope.jobs = res.data.jobs;
});
}]);
angular.module('RevenueChartCtrl', []).controller('RevenueChartController', ['$scope', '$stateParams', '$element', '$http', function($scope, $stateParams, $element, $http) {
var ctx = document.getElementById("skillsTrends");
var myChart = new Chart(ctx, {
type: 'bar',
options: {
tooltips: {
mode: 'label',
bodySpacing: 10,
cornerRadius: 0,
titleMarginBottom: 15
},
scales: {
xAxes: [{
ticks: {
}
}],
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 5000,
userCallback: function(value, index, values) {
// Convert the number to a string and splite the string every 3 charaters from the end
value = value.toString();
value = value.split(/(?=(?:...)*$)/);
// Convert the array to a string and format the output
value = value.join('.');
return '$' + value;
}
}
}]
},
},
data: {
labels: ['9/2015', '10/2015', '11/2015', '12/2015', '1/2016', '02/2016'],
datasets: [
{
label: "Average Monthly Revenue",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [9010.00, 22050.00, 16690.00, 17402.50, 20250.00, 28820.00],
spanGaps: false,
},
]
}
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment