You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.7 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. <title>amCharts examples</title>
  6. <link rel="stylesheet" href="style.css" type="text/css">
  7. <script src="../amcharts/amcharts.js" type="text/javascript"></script>
  8. <script src="../amcharts/serial.js" type="text/javascript"></script>
  9. <script>
  10. var chart;
  11. var chartData = [];
  12. var chartCursor;
  13. AmCharts.ready(function () {
  14. // generate some data first
  15. generateChartData();
  16. // SERIAL CHART
  17. chart = new AmCharts.AmSerialChart();
  18. chart.dataProvider = chartData;
  19. chart.categoryField = "date";
  20. chart.balloon.bulletSize = 5;
  21. // listen for "dataUpdated" event (fired when chart is rendered) and call zoomChart method when it happens
  22. chart.addListener("dataUpdated", zoomChart);
  23. // AXES
  24. // category
  25. var categoryAxis = chart.categoryAxis;
  26. categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
  27. categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
  28. categoryAxis.dashLength = 1;
  29. categoryAxis.minorGridEnabled = true;
  30. categoryAxis.twoLineMode = true;
  31. categoryAxis.dateFormats = [{
  32. period: 'fff',
  33. format: 'JJ:NN:SS'
  34. }, {
  35. period: 'ss',
  36. format: 'JJ:NN:SS'
  37. }, {
  38. period: 'mm',
  39. format: 'JJ:NN'
  40. }, {
  41. period: 'hh',
  42. format: 'JJ:NN'
  43. }, {
  44. period: 'DD',
  45. format: 'DD'
  46. }, {
  47. period: 'WW',
  48. format: 'DD'
  49. }, {
  50. period: 'MM',
  51. format: 'MMM'
  52. }, {
  53. period: 'YYYY',
  54. format: 'YYYY'
  55. }];
  56. categoryAxis.axisColor = "#DADADA";
  57. // value
  58. var valueAxis = new AmCharts.ValueAxis();
  59. valueAxis.axisAlpha = 0;
  60. valueAxis.dashLength = 1;
  61. chart.addValueAxis(valueAxis);
  62. // GRAPH
  63. var graph = new AmCharts.AmGraph();
  64. graph.title = "red line";
  65. graph.valueField = "visits";
  66. graph.bullet = "round";
  67. graph.bulletBorderColor = "#FFFFFF";
  68. graph.bulletBorderThickness = 2;
  69. graph.bulletBorderAlpha = 1;
  70. graph.lineThickness = 2;
  71. graph.lineColor = "#5fb503";
  72. graph.negativeLineColor = "#efcc26";
  73. graph.hideBulletsCount = 50; // this makes the chart to hide bullets when there are more than 50 series in selection
  74. chart.addGraph(graph);
  75. // CURSOR
  76. chartCursor = new AmCharts.ChartCursor();
  77. chartCursor.cursorPosition = "mouse";
  78. chartCursor.pan = true; // set it to fals if you want the cursor to work in "select" mode
  79. chart.addChartCursor(chartCursor);
  80. // SCROLLBAR
  81. var chartScrollbar = new AmCharts.ChartScrollbar();
  82. chart.addChartScrollbar(chartScrollbar);
  83. chart.creditsPosition = "bottom-right";
  84. // WRITE
  85. chart.write("chartdiv");
  86. });
  87. // generate some random data, quite different range
  88. function generateChartData() {
  89. var firstDate = new Date();
  90. firstDate.setDate(firstDate.getDate() - 500);
  91. for (var i = 0; i < 500; i++) {
  92. // we create date objects here. In your data, you can have date strings
  93. // and then set format of your dates using chart.dataDateFormat property,
  94. // however when possible, use date objects, as this will speed up chart rendering.
  95. var newDate = new Date(firstDate);
  96. newDate.setDate(newDate.getDate() + i);
  97. var visits = Math.round(Math.random() * 40) - 20;
  98. chartData.push({
  99. date: newDate,
  100. visits: visits
  101. });
  102. }
  103. }
  104. // this method is called when chart is first inited as we listen for "dataUpdated" event
  105. function zoomChart() {
  106. // different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
  107. chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
  108. }
  109. // changes cursor mode from pan to select
  110. function setPanSelect() {
  111. if (document.getElementById("rb1").checked) {
  112. chartCursor.pan = false;
  113. chartCursor.zoomable = true;
  114. } else {
  115. chartCursor.pan = true;
  116. }
  117. chart.validateNow();
  118. }
  119. </script>
  120. </head>
  121. <body>
  122. <div id="chartdiv" style="width: 100%; height: 400px;"></div>
  123. <div style="margin-left:35px;">
  124. <input type="radio" name="group" id="rb1" onclick="setPanSelect()">Select
  125. <input type="radio" checked="true" name="group" id="rb2" onclick="setPanSelect()">Pan
  126. </div>
  127. </body>
  128. </html>