serial3.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  6. <title>amCharts Responsive Example</title>
  7. <script src="http://www.amcharts.com/lib/3/amcharts.js"></script>
  8. <script src="http://www.amcharts.com/lib/3/serial.js"></script>
  9. <script src="../responsive.min.js"></script>
  10. <style>
  11. body, html {
  12. height: 100%;
  13. padding: 0;
  14. margin: 0;
  15. }
  16. </style>
  17. <script>
  18. var chartData = [];
  19. generateChartData();
  20. var chart = AmCharts.makeChart("chartdiv", {
  21. "type": "serial",
  22. "dataProvider": chartData,
  23. "categoryField": "date",
  24. "categoryAxis": {
  25. "parseDates": true,
  26. "gridAlpha": 0.15,
  27. "minorGridEnabled": true,
  28. "axisColor": "#DADADA"
  29. },
  30. "valueAxes": [{
  31. "axisAlpha": 0.2,
  32. "id": "v1"
  33. }],
  34. "graphs": [{
  35. "title": "red line",
  36. "id": "g1",
  37. "valueAxis": "v1",
  38. "valueField": "visits",
  39. "bullet": "round",
  40. "bulletBorderColor": "#FFFFFF",
  41. "bulletBorderAlpha": 1,
  42. "lineThickness": 2,
  43. "lineColor": "#b5030d",
  44. "negativeLineColor": "#0352b5",
  45. "balloonText": "[[category]]<br><b><span style='font-size:14px;'>value: [[value]]</span></b>"
  46. }],
  47. "chartCursor": {
  48. "fullWidth": true,
  49. "cursorAlpha": 0.1
  50. },
  51. "chartScrollbar": {
  52. "scrollbarHeight": 40,
  53. "color": "#FFFFFF",
  54. "autoGridCount": true,
  55. "graph": "g1"
  56. },
  57. "mouseWheelZoomEnabled": true,
  58. "responsive": {
  59. "enabled": true
  60. }
  61. });
  62. chart.addListener("dataUpdated", zoomChart);
  63. // generate some random data, quite different range
  64. function generateChartData() {
  65. var firstDate = new Date();
  66. firstDate.setDate(firstDate.getDate() - 500);
  67. for (var i = 0; i < 500; i++) {
  68. // we create date objects here. In your data, you can have date strings
  69. // and then set format of your dates using chart.dataDateFormat property,
  70. // however when possible, use date objects, as this will speed up chart rendering.
  71. var newDate = new Date(firstDate);
  72. newDate.setDate(newDate.getDate() + i);
  73. var visits = Math.round(Math.random() * 40) - 20;
  74. chartData.push({
  75. date: newDate,
  76. visits: visits
  77. });
  78. }
  79. }
  80. // this method is called when chart is first inited as we listen for "dataUpdated" event
  81. function zoomChart() {
  82. // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
  83. chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
  84. }
  85. </script>
  86. </head>
  87. <body>
  88. <div id="chartdiv" style="width: 100%; height: 100%;"></div>
  89. </body>
  90. </html>