bar.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*=========================================================================================
  2. File Name: bar.js
  3. Description: Chartjs bar chart
  4. ----------------------------------------------------------------------------------------
  5. Item Name: Robust - Responsive Admin Theme
  6. Version: 1.2
  7. Author: PIXINVENT
  8. Author URL: http://www.themeforest.net/user/pixinvent
  9. ==========================================================================================*/
  10. // Bar chart
  11. // ------------------------------
  12. $(window).on("load", function(){
  13. //Get the context of the Chart canvas element we want to select
  14. var ctx = $("#bar-chart");
  15. // Chart Options
  16. var chartOptions = {
  17. // Elements options apply to all of the options unless overridden in a dataset
  18. // In this case, we are setting the border of each horizontal bar to be 2px wide and green
  19. elements: {
  20. rectangle: {
  21. borderWidth: 2,
  22. borderColor: 'rgb(0, 255, 0)',
  23. borderSkipped: 'left'
  24. }
  25. },
  26. responsive: true,
  27. maintainAspectRatio: false,
  28. responsiveAnimationDuration:500,
  29. legend: {
  30. position: 'top',
  31. },
  32. scales: {
  33. xAxes: [{
  34. display: true,
  35. gridLines: {
  36. color: "#f3f3f3",
  37. drawTicks: false,
  38. },
  39. scaleLabel: {
  40. display: true,
  41. }
  42. }],
  43. yAxes: [{
  44. display: true,
  45. gridLines: {
  46. color: "#f3f3f3",
  47. drawTicks: false,
  48. },
  49. scaleLabel: {
  50. display: true,
  51. }
  52. }]
  53. },
  54. title: {
  55. display: false,
  56. text: 'Chart.js Horizontal Bar Chart'
  57. }
  58. };
  59. // Chart Data
  60. var chartData = {
  61. labels: ["January", "February", "March", "April"],
  62. datasets: [{
  63. label: "My First dataset",
  64. data: [65, 59, 80, 81],
  65. backgroundColor: "#673AB7",
  66. hoverBackgroundColor: "rgba(103,58,183,.9)",
  67. borderColor: "transparent"
  68. }, {
  69. label: "My Second dataset",
  70. data: [28, 48, 40, 19],
  71. backgroundColor: "#E91E63",
  72. hoverBackgroundColor: "rgba(233,30,99,.9)",
  73. borderColor: "transparent"
  74. }]
  75. };
  76. var config = {
  77. type: 'horizontalBar',
  78. // Chart Options
  79. options : chartOptions,
  80. data : chartData
  81. };
  82. // Create the chart
  83. var lineChart = new Chart(ctx, config);
  84. });