chart_gauge.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <html>
  2. <head>
  3. <link href="/css/c3.css" rel="stylesheet" type="text/css">
  4. </head>
  5. <body>
  6. <div id="chart"></div>
  7. <div id="chart1"></div>
  8. <div id="chart2"></div>
  9. <div id="chart3"></div>
  10. <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
  11. <script src="/js/c3.js"></script>
  12. <script>
  13. var chart = c3.generate({
  14. data: {
  15. columns: [
  16. [ 'data', 91.4 ]
  17. ],
  18. type: 'gauge',
  19. onmouseover: function (d, i) { console.log("onmouseover", d, i, this); },
  20. onmouseout: function (d, i) { console.log("onmouseout", d, i, this); },
  21. onclick: function (d, i) { console.log("onclick", d, i, this); },
  22. },
  23. gauge: {
  24. label: {
  25. // format: function(value, ratio) {
  26. // return value;
  27. // },
  28. // extents: function (value, isMax) {
  29. // return value + '%';
  30. // },
  31. // show: false // to turn off the min/max labels.
  32. },
  33. // min: 0, // 0 is default, //can handle negative min e.g. vacuum / voltage / current flow / rate of change
  34. // max: 100, // 100 is default
  35. // units: ' %',
  36. // width: 39 // for adjusting arc thickness
  37. },
  38. color: {
  39. pattern: ['#FF0000', '#F6C600', '#60B044'], // the three color levels for the percentage values.
  40. threshold: {
  41. // unit: 'value', // percentage is default
  42. // max: 200, // 100 is default
  43. values: [30, 60, 90] // alternate first value is 'value'
  44. }
  45. }
  46. });
  47. var chart1 = c3.generate({
  48. bindto: '#chart1',
  49. data: {
  50. columns: [
  51. ['data', 75.0]
  52. ],
  53. type: 'gauge',
  54. },
  55. gauge: {
  56. min: 50,
  57. max: 100
  58. }
  59. });
  60. var chart2 = c3.generate({
  61. bindto: '#chart2',
  62. data: {
  63. columns: [
  64. ['data', 0.0]
  65. ],
  66. type: 'gauge',
  67. },
  68. gauge: {
  69. min: -100,
  70. max: 100
  71. }
  72. });
  73. var chart3 = c3.generate({
  74. bindto: '#chart3',
  75. data: {
  76. columns: [
  77. ['data', -75.0]
  78. ],
  79. type: 'gauge',
  80. },
  81. gauge: {
  82. min: -100,
  83. max: -50
  84. }
  85. });
  86. var cycleDemo = function () {
  87. setTimeout(function () {
  88. d3.select('#chart .c3-chart-arcs-background')
  89. .transition()
  90. .style('fill', '#333');
  91. }, 1000);
  92. setTimeout(function () {
  93. chart.load({
  94. columns: [[ 'data', 10 ]]
  95. });
  96. }, 2000);
  97. setTimeout(function () {
  98. chart.load({
  99. columns: [[ 'data', 50 ]]
  100. });
  101. }, 3000);
  102. setTimeout(function () {
  103. chart.load({
  104. columns: [[ 'data', 91.4 ]]
  105. });
  106. }, 4000);
  107. setTimeout(function () {
  108. d3.select('#chart .c3-chart-arcs-background')
  109. .transition()
  110. .style('fill', '#e0e0e0');
  111. }, 5000);
  112. setTimeout(function () {
  113. chart.load({
  114. columns: [[ 'data', 0 ]]
  115. });
  116. }, 6000);
  117. setTimeout(function () {
  118. chart.load({
  119. columns: [[ 'data', 50 ]]
  120. });
  121. }, 7000);
  122. setTimeout(function () {
  123. chart.load({
  124. columns: [[ 'data', 91.4 ]]
  125. });
  126. }, 8000);
  127. setTimeout(function () {
  128. chart.load({
  129. columns: [[ 'data', 0 ]]
  130. });
  131. }, 9000);
  132. setTimeout(function () {
  133. chart.load({
  134. columns: [[ 'data', 50 ]]
  135. });
  136. }, 10000);
  137. setTimeout(function () {
  138. chart.load({
  139. columns: [[ 'data', 91.4 ]]
  140. });
  141. }, 11000);
  142. setTimeout(function () {
  143. chart.load({
  144. columns: [[ 'data', 0 ]]
  145. });
  146. }, 12000);
  147. setTimeout(function () {
  148. chart.load({
  149. columns: [[ 'data', 50 ]]
  150. });
  151. }, 13000);
  152. setTimeout(function () {
  153. chart.load({
  154. columns: [[ 'data', 91.4 ]]
  155. });
  156. }, 14000);
  157. }
  158. cycleDemo();
  159. // setInterval(cycleDemo, 30000);
  160. </script>
  161. </body>
  162. </html>