nescafe2002

Untitled

Jan 6th, 2017
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <head>
  2. </head>
  3. <body>
  4. <!-- Styles -->
  5. <style>
  6. #chartdiv {
  7.   width: 100%;
  8.   height: 500px;
  9. }
  10. </style>
  11.  
  12. <!-- Resources -->
  13. <script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
  14. <script src="https://www.amcharts.com/lib/3/serial.js"></script>
  15. <script src="https://www.amcharts.com/lib/3/amstock.js"></script>
  16. <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
  17. <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
  18. <script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
  19.  
  20. <!-- Chart code -->
  21. <script>
  22. // <!--
  23. var chartData1 = [];
  24. var chartData2 = [];
  25. var chartData3 = [];
  26. var chartData4 = [];
  27.  
  28. generateChartData();
  29.  
  30. function generateChartData() {
  31.  var firstDate = new Date();
  32.  firstDate.setDate( firstDate.getDate() - 500 );
  33.  firstDate.setHours( 0, 0, 0, 0 );
  34.  
  35.  for ( var i = 0; i < 500; i++ ) {
  36.    var newDate = new Date( firstDate );
  37.    newDate.setDate( newDate.getDate() + i );
  38.  
  39.    var a1 = Math.round( Math.random() * ( 40 + i ) ) + 100 + i;
  40.    var b1 = Math.round( Math.random() * ( 1000 + i ) ) + 500 + i * 2;
  41.  
  42.    var a2 = Math.round( Math.random() * ( 100 + i ) ) + 200 + i;
  43.    var b2 = Math.round( Math.random() * ( 1000 + i ) ) + 600 + i * 2;
  44.  
  45.    var a3 = Math.round( Math.random() * ( 100 + i ) ) + 200;
  46.    var b3 = Math.round( Math.random() * ( 1000 + i ) ) + 600 + i * 2;
  47.  
  48.    var a4 = Math.round( Math.random() * ( 100 + i ) ) + 200 + i;
  49.    var b4 = Math.round( Math.random() * ( 100 + i ) ) + 600 + i;
  50.  
  51.    chartData1.push( {
  52.      "date": newDate,
  53.      "value": a1,
  54.      "volume": b1
  55.    } );
  56.    chartData2.push( {
  57.      "date": newDate,
  58.      "value": a2,
  59.      "volume": b2
  60.    } );
  61.    chartData3.push( {
  62.      "date": newDate,
  63.      "value": a3,
  64.      "volume": b3
  65.    } );
  66.    chartData4.push( {
  67.      "date": newDate,
  68.      "value": a4,
  69.      "volume": b4
  70.    } );
  71.  }
  72. }
  73.  
  74. var chart = AmCharts.makeChart( "chartdiv", {
  75.  "type": "stock",
  76.  "theme": "light",
  77.  "dataSets": [ {
  78.      "title": "first data set",
  79.      "fieldMappings": [ {
  80.        "fromField": "value",
  81.        "toField": "value"
  82.      }, {
  83.        "fromField": "volume",
  84.        "toField": "volume"
  85.      } ],
  86.      "dataProvider": chartData1,
  87.      "categoryField": "date"
  88.    }, {
  89.      "title": "second data set",
  90.      "fieldMappings": [ {
  91.        "fromField": "value",
  92.        "toField": "value"
  93.      }, {
  94.        "fromField": "volume",
  95.        "toField": "volume"
  96.      } ],
  97.      "dataProvider": chartData2,
  98.      "categoryField": "date"
  99.    }, {
  100.      "title": "third data set",
  101.      "fieldMappings": [ {
  102.        "fromField": "value",
  103.        "toField": "value"
  104.      }, {
  105.        "fromField": "volume",
  106.        "toField": "volume"
  107.      } ],
  108.      "dataProvider": chartData3,
  109.      "categoryField": "date"
  110.    }, {
  111.      "title": "fourth data set",
  112.      "fieldMappings": [ {
  113.        "fromField": "value",
  114.        "toField": "value"
  115.      }, {
  116.        "fromField": "volume",
  117.        "toField": "volume"
  118.      } ],
  119.      "dataProvider": chartData4,
  120.      "categoryField": "date"
  121.    }
  122.  ],
  123.  
  124.  "panels": [ {
  125.    "showCategoryAxis": false,
  126.    "title": "Value",
  127.    "percentHeight": 70,
  128.    "stockGraphs": [ {
  129.      "id": "g1",
  130.      "valueField": "value",
  131.      "comparable": true,
  132.      "compareField": "value",
  133.      "balloonText": "[[title]]:<b>[[value]]</b>",
  134.      "compareGraphBalloonText": "[[title]]:<b>[[value]]</b>"
  135.    } ],
  136.    "stockLegend": {
  137.      "periodValueTextComparing": "[[percents.value.close]]%",
  138.      "periodValueTextRegular": "[[value.close]]"
  139.    }
  140.  }, {
  141.    "title": "Volume",
  142.    "percentHeight": 30,
  143.    "stockGraphs": [ {
  144.      "valueField": "volume",
  145.      "type": "column",
  146.      "showBalloon": false,
  147.      "fillAlphas": 1
  148.    } ],
  149.    "stockLegend": {
  150.      "periodValueTextRegular": "[[value.close]]"
  151.    }
  152.  } ],
  153.  
  154.  "chartScrollbarSettings": {
  155.    "graph": "g1"
  156.  },
  157.  
  158.  "chartCursorSettings": {
  159.    "valueBalloonsEnabled": true,
  160.    "fullWidth": true,
  161.    "cursorAlpha": 0.1,
  162.    "valueLineBalloonEnabled": true,
  163.    "valueLineEnabled": true,
  164.    "valueLineAlpha": 0.5
  165.  },
  166.  
  167.  "periodSelector": {
  168.    "position": "left",
  169.    "periods": [ {
  170.      "period": "MM",
  171.      "selected": true,
  172.      "count": 1,
  173.      "label": "1 month"
  174.    }, {
  175.      "period": "YYYY",
  176.      "count": 1,
  177.      "label": "1 year"
  178.    }, {
  179.      "period": "YTD",
  180.      "label": "YTD"
  181.    }, {
  182.      "period": "MAX",
  183.      "label": "MAX"
  184.    } ]
  185.  },
  186.  
  187.  "dataSetSelector": {
  188.    "position": "left"
  189.  },
  190.  
  191.  "export": {
  192.    "enabled": true
  193.  }
  194. } );
  195. // -->
  196. </script>
  197.  
  198. <!-- HTML -->
  199. <div id="chartdiv"></div>
  200. </body>
Advertisement
Add Comment
Please, Sign In to add comment