serial3.html 2.9 KB

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