Last active
December 17, 2015 01:28
-
-
Save SebastianTroc/5528230 to your computer and use it in GitHub Desktop.
Generator liczb pseudolosowych z wykresem liczb wylosowanych jednostek od 1 do 100
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Generator liczb pseudolosowaych</title> | |
| <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
| <script src="http://www.amcharts.com/lib/amcharts.js" type="text/javascript"></script> | |
| </head> | |
| <body> | |
| <div id="chartdiv" style="width: 100%; height: 500px;"></div> | |
| <script src="losowanie.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| var tab = []; | |
| var chart; | |
| // zapelnianie tablicy zerami | |
| for (var i = 0; i < 100; i++) { | |
| tab[i] = 0; | |
| } | |
| // losowanie liczb i inkrementowanie liczby wylosowanych jednostek | |
| for (var i = 0; i < 10000; i++) { | |
| var rand = Math.floor(Math.random() * 100) + 1; | |
| // console.log(i+1 + ' : ' + rand); | |
| tab[rand-1]++; | |
| } | |
| // wyswietlanie ilosci poszczegolnych trafien w konsoli | |
| for (var i = 0; i < 100; i++) { | |
| console.log(i+1 + " : " + tab[i]); | |
| } | |
| var chartData = []; | |
| // wypelnianie | |
| for (var i = 0; i < 100; i++) { | |
| chartData.push({ | |
| number: i+1, | |
| hits: tab[i] | |
| }); | |
| } | |
| // console.log(chartData); | |
| AmCharts.ready(function() { | |
| // SERIAL CHART | |
| chart = new AmCharts.AmSerialChart(); | |
| chart.dataProvider = chartData; | |
| chart.categoryField = "number"; | |
| chart.startDuration = 1; | |
| // AXES | |
| var categoryAxis = chart.categoryAxis; | |
| categoryAxis.labelRotation = 90; | |
| categoryAxis.gridPosition = "start"; | |
| // GRAPH | |
| var graph = new AmCharts.AmGraph(); | |
| graph.valueField = "hits"; | |
| graph.balloonText = "[[category]]: [[value]]"; | |
| graph.type = "column"; | |
| graph.lineAlpha = 0; | |
| graph.fillAlphas = 0.8; | |
| chart.addGraph(graph); | |
| chart.write("chartdiv"); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment