|
|
|
|
@ -3,14 +3,12 @@ function myScatterPlot() {
|
|
|
|
|
console.log("entering...");
|
|
|
|
|
|
|
|
|
|
//debugger;
|
|
|
|
|
d3.csv("./dataset.csv", function(error, data) {
|
|
|
|
|
const myPromise = d3.csv("./dataset.csv");
|
|
|
|
|
|
|
|
|
|
myPromise.then((data) => {
|
|
|
|
|
|
|
|
|
|
//debugger;
|
|
|
|
|
console.log("callback...")
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
console.log("callback error...")
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var i=0;
|
|
|
|
|
data.forEach(d => {
|
|
|
|
|
@ -22,11 +20,17 @@ function myScatterPlot() {
|
|
|
|
|
i++;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// plot to view
|
|
|
|
|
plot(dataset);
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
alert("File Missing!!!")
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ?? why never plot using update csv data???
|
|
|
|
|
console.log(dataset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Plot the scatter plot graph given the dataset */
|
|
|
|
|
function plot(dataset) {
|
|
|
|
|
// constants
|
|
|
|
|
const WIDTH = 600;
|
|
|
|
|
const HEIGHT = 600;
|
|
|
|
|
@ -43,6 +47,7 @@ function myScatterPlot() {
|
|
|
|
|
.domain([0, d3.max(dataset, d => d[1])])
|
|
|
|
|
.range([HEIGHT - PADDING, PADDING]); // reverse the range as view coordinate start from top-left
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create SVG element
|
|
|
|
|
var svg = d3.select("body")
|
|
|
|
|
.append("svg")
|
|
|
|
|
@ -73,7 +78,7 @@ function myScatterPlot() {
|
|
|
|
|
// draw axes
|
|
|
|
|
// x axis : transform drawing from top to bottom
|
|
|
|
|
svg.append("g")
|
|
|
|
|
.attr("transform", `translate(0,${HEIGHT-PADDING})`)
|
|
|
|
|
.attr("transform", `translate(0,${HEIGHT - PADDING})`)
|
|
|
|
|
.call(d3.axisBottom()
|
|
|
|
|
.scale(xScale));
|
|
|
|
|
// y axis : transform the drawing to display the scale number
|
|
|
|
|
|