5 <title>Scatter Chart Multi Axis
</title>
6 <script src=
"../dist/Chart.bundle.js"></script>
7 <script src=
"http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
10 -moz-user-select: none;
11 -webkit-user-select: none;
12 -ms-user-select: none;
18 <div style=
"width:75%">
20 <canvas id=
"canvas"></canvas>
23 <button id=
"randomizeData">Randomize Data
</button>
25 var randomScalingFactor = function() {
26 return (Math
.random() > 0.5 ? 1.0 : -1.0) * Math
.round(Math
.random() * 100);
28 var randomColor = function(opacity
) {
29 return 'rgba(' + Math
.round(Math
.random() * 255) + ',' + Math
.round(Math
.random() * 255) + ',' + Math
.round(Math
.random() * 255) + ',' + (opacity
|| '.3') + ')';
32 var scatterChartData
= {
34 label
: "My First dataset",
38 x
: randomScalingFactor(),
39 y
: randomScalingFactor(),
41 x
: randomScalingFactor(),
42 y
: randomScalingFactor(),
44 x
: randomScalingFactor(),
45 y
: randomScalingFactor(),
47 x
: randomScalingFactor(),
48 y
: randomScalingFactor(),
50 x
: randomScalingFactor(),
51 y
: randomScalingFactor(),
53 x
: randomScalingFactor(),
54 y
: randomScalingFactor(),
56 x
: randomScalingFactor(),
57 y
: randomScalingFactor(),
60 label
: "My Second dataset",
64 x
: randomScalingFactor(),
65 y
: randomScalingFactor(),
67 x
: randomScalingFactor(),
68 y
: randomScalingFactor(),
70 x
: randomScalingFactor(),
71 y
: randomScalingFactor(),
73 x
: randomScalingFactor(),
74 y
: randomScalingFactor(),
76 x
: randomScalingFactor(),
77 y
: randomScalingFactor(),
79 x
: randomScalingFactor(),
80 y
: randomScalingFactor(),
82 x
: randomScalingFactor(),
83 y
: randomScalingFactor(),
88 $.each(scatterChartData
.datasets
, function(i
, dataset
) {
89 dataset
.borderColor
= randomColor(0.4);
90 dataset
.backgroundColor
= randomColor(0.1);
91 dataset
.pointBorderColor
= randomColor(0.7);
92 dataset
.pointBackgroundColor
= randomColor(0.5);
93 dataset
.pointBorderWidth
= 1;
96 window
.onload = function() {
97 var ctx
= document
.getElementById("canvas").getContext("2d");
98 window
.myScatter
= Chart
.Scatter(ctx
, {
99 data
: scatterChartData
,
105 text
: 'Chart.js Scatter Chart - Multi Axis'
111 zeroLineColor
: "rgba(0,0,0,1)"
115 type
: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
120 type
: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
126 // grid line settings
128 drawOnChartArea
: false, // only want the grid lines for one axis to show up
136 $('#randomizeData').click(function() {
137 scatterChartData
.datasets
[0].data
= [{
138 x
: randomScalingFactor(),
139 y
: randomScalingFactor(),
141 x
: randomScalingFactor(),
142 y
: randomScalingFactor(),
144 x
: randomScalingFactor(),
145 y
: randomScalingFactor(),
147 x
: randomScalingFactor(),
148 y
: randomScalingFactor(),
150 x
: randomScalingFactor(),
151 y
: randomScalingFactor(),
153 x
: randomScalingFactor(),
154 y
: randomScalingFactor(),
156 x
: randomScalingFactor(),
157 y
: randomScalingFactor(),
159 scatterChartData
.datasets
[1].data
= [{
160 x
: randomScalingFactor(),
161 y
: randomScalingFactor(),
163 x
: randomScalingFactor(),
164 y
: randomScalingFactor(),
166 x
: randomScalingFactor(),
167 y
: randomScalingFactor(),
169 x
: randomScalingFactor(),
170 y
: randomScalingFactor(),
172 x
: randomScalingFactor(),
173 y
: randomScalingFactor(),
175 x
: randomScalingFactor(),
176 y
: randomScalingFactor(),
178 x
: randomScalingFactor(),
179 y
: randomScalingFactor(),
181 window
.myScatter
.update();