Skip to content

Instantly share code, notes, and snippets.

@Bruce0203
Created August 5, 2022 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bruce0203/21a1190be2feea0e87a442a037115a5e to your computer and use it in GitHub Desktop.
Save Bruce0203/21a1190be2feea0e87a442a037115a5e to your computer and use it in GitHub Desktop.
<div>
<canvas id="myChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
var labels = Array()
var num = getRandomInt(1000000)
function getCollatz() {while (num != 1) {
if (num % 2 == 0) {
num /= 2
} else {
num = num * 3+ 1
}
labels.push(num)
}}
getCollatz()
setTimeout(() => {
// window.location.reload();
}, 1)
const data = {
labels: labels,
datasets: [{
label: 'collatz graph',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: labels,
}]
};
const config = {
type: 'line',
data: data,
options: {}
};
</script>
<script>
const myChart = new Chart(
document.getElementById('myChart'),
config
);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment