-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<title>Bar Chart Zoom</title> | ||
<script src="../node_modules/chart.js/dist/Chart.bundle.js"></script> | ||
<script src="../node_modules/hammerjs/hammer.min.js"></script> | ||
<script src="../Chart.Zoom.js"></script> | ||
<style> | ||
canvas { | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="container" style="width: 75%;"> | ||
<canvas id="canvas"></canvas> | ||
</div> | ||
<script> | ||
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; | ||
|
||
var randomScalingFactor = function() { | ||
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100); | ||
}; | ||
var randomColorFactor = function() { | ||
return Math.round(Math.random() * 255); | ||
}; | ||
var randomColor = function() { | ||
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)'; | ||
}; | ||
|
||
var barChartData = { | ||
labels: ["January", "February", "March", "April", "May", "June", "July"], | ||
datasets: [{ | ||
label: 'Dataset 1', | ||
backgroundColor: "rgba(220,220,220,0.5)", | ||
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] | ||
}, { | ||
hidden: true, | ||
label: 'Dataset 2', | ||
backgroundColor: "rgba(151,187,205,0.5)", | ||
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] | ||
}, { | ||
label: 'Dataset 3', | ||
backgroundColor: "rgba(151,187,205,0.5)", | ||
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] | ||
}] | ||
|
||
}; | ||
|
||
window.onload = function() { | ||
var ctx = document.getElementById("canvas").getContext("2d"); | ||
window.myBar = new Chart(ctx, { | ||
type: 'bar', | ||
data: barChartData, | ||
options: { | ||
// Elements options apply to all of the options unless overridden in a dataset | ||
// In this case, we are setting the border of each bar to be 2px wide and green | ||
elements: { | ||
rectangle: { | ||
borderWidth: 2, | ||
borderColor: 'rgb(0, 255, 0)', | ||
borderSkipped: 'bottom' | ||
} | ||
}, | ||
responsive: true, | ||
legend: { | ||
position: 'top', | ||
}, | ||
title: { | ||
display: true, | ||
text: 'Chart.js Bar Chart' | ||
}, | ||
pan: { | ||
enabled: true, | ||
mode: 'y' | ||
}, | ||
zoom: { | ||
enabled: true, | ||
mode: 'y', | ||
limits: { | ||
max: 10, | ||
min: 0.5 | ||
} | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
ticks: { | ||
min: 'February', | ||
max: 'June' | ||
} | ||
}] | ||
} | ||
} | ||
}); | ||
|
||
}; | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<title>Scatter Chart</title> | ||
<script src="../node_modules/chart.js/dist/Chart.bundle.js"></script> | ||
<script src="../node_modules/hammerjs/hammer.min.js"></script> | ||
<script src="../Chart.Zoom.js"></script> | ||
<style> | ||
canvas { | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div style="width:75%"> | ||
<div> | ||
<canvas id="canvas"></canvas> | ||
</div> | ||
</div> | ||
<script> | ||
var randomScalingFactor = function() { | ||
return Math.round(Math.random() * 10.0) * Math.pow(10, Math.ceil(Math.random() * 5)); | ||
}; | ||
var randomColor = function(opacity) { | ||
return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')'; | ||
}; | ||
|
||
var scatterChartData = { | ||
datasets: [{ | ||
label: "V(node2)", | ||
data: [{ | ||
x: 1, | ||
y: -1.711e-2, | ||
}, { | ||
x: 1.26, | ||
y: -2.708e-2, | ||
}, { | ||
x: 1.58, | ||
y: -4.285e-2, | ||
}, { | ||
x: 2.0, | ||
y: -6.772e-2, | ||
}, { | ||
x: 2.51, | ||
y: -1.068e-1, | ||
}, { | ||
x: 3.16, | ||
y: -1.681e-1, | ||
}, { | ||
x: 3.98, | ||
y: -2.635e-1, | ||
}, { | ||
x: 5.01, | ||
y: -4.106e-1, | ||
}, { | ||
x: 6.31, | ||
y: -6.339e-1, | ||
}, { | ||
x: 7.94, | ||
y: -9.659e-1, | ||
}, { | ||
x: 10.00, | ||
y: -1.445, | ||
}, { | ||
x: 12.6, | ||
y: -2.110, | ||
}, { | ||
x: 15.8, | ||
y: -2.992, | ||
}, { | ||
x: 20.0, | ||
y: -4.102, | ||
}, { | ||
x: 25.1, | ||
y: -5.429, | ||
}, { | ||
x: 31.6, | ||
y: -6.944, | ||
}, { | ||
x: 39.8, | ||
y: -8.607, | ||
}, { | ||
x: 50.1, | ||
y: -1.038e1, | ||
}, { | ||
x: 63.1, | ||
y: -1.223e1, | ||
}, { | ||
x: 79.4, | ||
y: -1.413e1, | ||
}, { | ||
x: 100.00, | ||
y: -1.607e1, | ||
}, { | ||
x: 126, | ||
y: -1.803e1, | ||
}, { | ||
x: 158, | ||
y: -2e1, | ||
}, { | ||
x: 200, | ||
y: -2.199e1, | ||
}, { | ||
x: 251, | ||
y: -2.398e1, | ||
}, { | ||
x: 316, | ||
y: -2.597e1, | ||
}, { | ||
x: 398, | ||
y: -2.797e1, | ||
}, { | ||
x: 501, | ||
y: -2.996e1, | ||
}, { | ||
x: 631, | ||
y: -3.196e1, | ||
}, { | ||
x: 794, | ||
y: -3.396e1, | ||
}, { | ||
x: 1000, | ||
y: -3.596e1, | ||
},] | ||
}] | ||
}; | ||
|
||
scatterChartData.datasets.forEach(function(dataset) { | ||
dataset.borderColor = randomColor(0.4); | ||
dataset.backgroundColor = randomColor(0.1); | ||
dataset.pointBorderColor = randomColor(0.7); | ||
dataset.pointBackgroundColor = randomColor(0.5); | ||
dataset.pointBorderWidth = 1; | ||
}); | ||
|
||
window.onload = function() { | ||
var ctx = document.getElementById("canvas").getContext("2d"); | ||
window.myScatter = Chart.Scatter(ctx, { | ||
data: scatterChartData, | ||
options: { | ||
title: { | ||
display: true, | ||
text: 'Chart.js Scatter Chart - Logarithmic X-Axis' | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
type: 'logarithmic', | ||
position: 'bottom', | ||
ticks: { | ||
userCallback: function(tick) { | ||
var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick)))); | ||
if (remain === 1 || remain === 2 || remain === 5) { | ||
return tick.toString() + "Hz"; | ||
} | ||
return ''; | ||
}, | ||
maxRotation: 0 | ||
}, | ||
scaleLabel: { | ||
labelString: 'Frequency', | ||
display: true, | ||
}, | ||
}], | ||
yAxes: [{ | ||
type: 'linear', | ||
ticks: { | ||
userCallback: function(tick) { | ||
return tick.toFixed(0) + "dB"; | ||
} | ||
}, | ||
scaleLabel: { | ||
labelString: 'Voltage', | ||
display: true | ||
} | ||
}] | ||
}, | ||
pan: { | ||
enabled: true, | ||
mode: 'xy', | ||
limits: { | ||
xmin: 1e-4, | ||
ymin: -50, | ||
ymax: 10 | ||
}, | ||
xScale0: { | ||
max: 1e4 | ||
} | ||
}, | ||
zoom: { | ||
enabled: true, | ||
mode: 'xy', | ||
limits: { | ||
max: 10, | ||
min: 0.5 | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.