Built with blockbuilder.org
xxxxxxxxxx
<html>
<meta charset="utf-8">
<!-- Example based on https://bl.ocks.org/mbostock/3887118 -->
<!-- Tooltip example from https://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html -->
<!-- Coding style based on https://gist.github.com/mbostock/5977197 -->
<style>
body {
font: 11px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
.tooltip {
position: absolute;
width: 200px;
height: 28px;
pointer-events: none;
}
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
/*
* value accessor - returns the value to encode for a given data object.
* scale - maps value to a visual display encoding, such as a pixel position.
* map function - maps from data value to display value
* axis - sets up axis
*/
// setup x
var xValue = function(d) { return d.Calories;}, // data -> value
xScale = d3.scale.linear().range([0, width]), // value -> display
xMap = function(d) { return xScale(xValue(d));}, // data -> display
xAxis = d3.svg.axis().scale(xScale).orient("bottom");
// setup y
var yValue = function(d) { return d["Protein (g)"];}, // data -> value
yScale = d3.scale.linear().range([height, 0]), // value -> display
yMap = function(d) { return yScale(yValue(d));}, // data -> display
yAxis = d3.svg.axis().scale(yScale).orient("left");
// setup fill color
var cValue = function(d) { return d.Manufacturer;},
color = d3.scale.category10();
// add the graph canvas to the body of the webpage
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// add the tooltip area to the webpage
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// load data
//d3.csv("cereal.csv", function(error, data) {
var data = [
{
"Cereal Name": "100%_Bran",
"Manufacturer": "Nabisco",
"Type": "C",
"Calories": 70,
"Protein (g)": 4,
"Fat": 1,
"Sodium": 130,
"Dietary Fiber": 10,
"Carbs": 5,
"Sugars": 6,
"Display Shelf": 3,
"Potassium": 280,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.33
},
{
"Cereal Name": "100%_Natural_Bran",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 120,
"Protein (g)": 3,
"Fat": 5,
"Sodium": 15,
"Dietary Fiber": 2,
"Carbs": 8,
"Sugars": 8,
"Display Shelf": 3,
"Potassium": 135,
"Vitamins and Minerals": 0,
"Serving Size Weight": 1,
"Cups per Serving": -1
},
{
"Cereal Name": "All-Bran",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 70,
"Protein (g)": 4,
"Fat": 1,
"Sodium": 260,
"Dietary Fiber": 9,
"Carbs": 7,
"Sugars": 5,
"Display Shelf": 3,
"Potassium": 320,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.33
},
{
"Cereal Name": "All-Bran_with_Extra_Fiber",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 50,
"Protein (g)": 4,
"Fat": 0,
"Sodium": 140,
"Dietary Fiber": 14,
"Carbs": 8,
"Sugars": 0,
"Display Shelf": 3,
"Potassium": 330,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Almond_Delight",
"Manufacturer": "Ralston Purina",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 2,
"Sodium": 200,
"Dietary Fiber": 1,
"Carbs": 14,
"Sugars": 8,
"Display Shelf": 3,
"Potassium": -1,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Apple_Cinnamon_Cheerios",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 2,
"Sodium": 180,
"Dietary Fiber": 1.5,
"Carbs": 10.5,
"Sugars": 10,
"Display Shelf": 1,
"Potassium": 70,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Apple_Jacks",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 125,
"Dietary Fiber": 1,
"Carbs": 11,
"Sugars": 14,
"Display Shelf": 2,
"Potassium": 30,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Basic_4",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 130,
"Protein (g)": 3,
"Fat": 2,
"Sodium": 210,
"Dietary Fiber": 2,
"Carbs": 18,
"Sugars": 8,
"Display Shelf": 3,
"Potassium": 100,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.33,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Bran_Chex",
"Manufacturer": "Ralston Purina",
"Type": "C",
"Calories": 90,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 200,
"Dietary Fiber": 4,
"Carbs": 15,
"Sugars": 6,
"Display Shelf": 1,
"Potassium": 125,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Bran_Flakes",
"Manufacturer": "Post",
"Type": "C",
"Calories": 90,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 210,
"Dietary Fiber": 5,
"Carbs": 13,
"Sugars": 5,
"Display Shelf": 3,
"Potassium": 190,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Cap'n'Crunch",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 120,
"Protein (g)": 1,
"Fat": 2,
"Sodium": 220,
"Dietary Fiber": 0,
"Carbs": 12,
"Sugars": 12,
"Display Shelf": 2,
"Potassium": 35,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Cheerios",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 6,
"Fat": 2,
"Sodium": 290,
"Dietary Fiber": 2,
"Carbs": 17,
"Sugars": 1,
"Display Shelf": 1,
"Potassium": 105,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1.25
},
{
"Cereal Name": "Cinnamon_Toast_Crunch",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 120,
"Protein (g)": 1,
"Fat": 3,
"Sodium": 210,
"Dietary Fiber": 0,
"Carbs": 13,
"Sugars": 9,
"Display Shelf": 2,
"Potassium": 45,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Clusters",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 3,
"Fat": 2,
"Sodium": 140,
"Dietary Fiber": 2,
"Carbs": 13,
"Sugars": 7,
"Display Shelf": 3,
"Potassium": 105,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Cocoa_Puffs",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 1,
"Sodium": 180,
"Dietary Fiber": 0,
"Carbs": 12,
"Sugars": 13,
"Display Shelf": 2,
"Potassium": 55,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Corn_Chex",
"Manufacturer": "Ralston Purina",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 280,
"Dietary Fiber": 0,
"Carbs": 22,
"Sugars": 3,
"Display Shelf": 1,
"Potassium": 25,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Corn_Flakes",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 100,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 290,
"Dietary Fiber": 1,
"Carbs": 21,
"Sugars": 2,
"Display Shelf": 1,
"Potassium": 35,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Corn_Pops",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 0,
"Sodium": 90,
"Dietary Fiber": 1,
"Carbs": 13,
"Sugars": 12,
"Display Shelf": 2,
"Potassium": 20,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Count_Chocula",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 1,
"Sodium": 180,
"Dietary Fiber": 0,
"Carbs": 12,
"Sugars": 13,
"Display Shelf": 2,
"Potassium": 65,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Cracklin'_Oat_Bran",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 3,
"Fat": 3,
"Sodium": 140,
"Dietary Fiber": 4,
"Carbs": 10,
"Sugars": 7,
"Display Shelf": 3,
"Potassium": 160,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Cream_of_Wheat_(Quick)",
"Manufacturer": "Nabisco",
"Type": "H",
"Calories": 100,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 80,
"Dietary Fiber": 1,
"Carbs": 21,
"Sugars": 0,
"Display Shelf": 2,
"Potassium": -1,
"Vitamins and Minerals": 0,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Crispix",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 220,
"Dietary Fiber": 1,
"Carbs": 21,
"Sugars": 3,
"Display Shelf": 3,
"Potassium": 30,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Crispy_Wheat_&_Raisins",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 100,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 140,
"Dietary Fiber": 2,
"Carbs": 11,
"Sugars": 10,
"Display Shelf": 3,
"Potassium": 120,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Double_Chex",
"Manufacturer": "Ralston Purina",
"Type": "C",
"Calories": 100,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 190,
"Dietary Fiber": 1,
"Carbs": 18,
"Sugars": 5,
"Display Shelf": 3,
"Potassium": 80,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Froot_Loops",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 125,
"Dietary Fiber": 1,
"Carbs": 11,
"Sugars": 13,
"Display Shelf": 2,
"Potassium": 30,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Frosted_Flakes",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 0,
"Sodium": 200,
"Dietary Fiber": 1,
"Carbs": 14,
"Sugars": 11,
"Display Shelf": 1,
"Potassium": 25,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Frosted_Mini-Wheats",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 3,
"Carbs": 14,
"Sugars": 7,
"Display Shelf": 2,
"Potassium": 100,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.8
},
{
"Cereal Name": "Fruitful_Bran",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 120,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 240,
"Dietary Fiber": 5,
"Carbs": 14,
"Sugars": 12,
"Display Shelf": 3,
"Potassium": 190,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.33,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Fruity_Pebbles",
"Manufacturer": "Post",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 1,
"Sodium": 135,
"Dietary Fiber": 0,
"Carbs": 13,
"Sugars": 12,
"Display Shelf": 2,
"Potassium": 25,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Golden_Crisp",
"Manufacturer": "Post",
"Type": "C",
"Calories": 100,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 45,
"Dietary Fiber": 0,
"Carbs": 11,
"Sugars": 15,
"Display Shelf": 1,
"Potassium": 40,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.88
},
{
"Cereal Name": "Golden_Grahams",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 1,
"Sodium": 280,
"Dietary Fiber": 0,
"Carbs": 15,
"Sugars": 9,
"Display Shelf": 2,
"Potassium": 45,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Grape_Nuts_Flakes",
"Manufacturer": "Post",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 140,
"Dietary Fiber": 3,
"Carbs": 15,
"Sugars": 5,
"Display Shelf": 3,
"Potassium": 85,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.88
},
{
"Cereal Name": "Grape-Nuts",
"Manufacturer": "Post",
"Type": "C",
"Calories": 110,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 170,
"Dietary Fiber": 3,
"Carbs": 17,
"Sugars": 3,
"Display Shelf": 3,
"Potassium": 90,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.25
},
{
"Cereal Name": "Great_Grains_Pecan",
"Manufacturer": "Post",
"Type": "C",
"Calories": 120,
"Protein (g)": 3,
"Fat": 3,
"Sodium": 75,
"Dietary Fiber": 3,
"Carbs": 13,
"Sugars": 4,
"Display Shelf": 3,
"Potassium": 100,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.33
},
{
"Cereal Name": "Honey_Graham_Ohs",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 120,
"Protein (g)": 1,
"Fat": 2,
"Sodium": 220,
"Dietary Fiber": 1,
"Carbs": 12,
"Sugars": 11,
"Display Shelf": 2,
"Potassium": 45,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Honey_Nut_Cheerios",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 250,
"Dietary Fiber": 1.5,
"Carbs": 11.5,
"Sugars": 10,
"Display Shelf": 1,
"Potassium": 90,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Honey-comb",
"Manufacturer": "Post",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 0,
"Sodium": 180,
"Dietary Fiber": 0,
"Carbs": 14,
"Sugars": 11,
"Display Shelf": 1,
"Potassium": 35,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1.33
},
{
"Cereal Name": "Just_Right_Crunchy__Nuggets",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 170,
"Dietary Fiber": 1,
"Carbs": 17,
"Sugars": 6,
"Display Shelf": 3,
"Potassium": 60,
"Vitamins and Minerals": 100,
"Serving Size Weight": 1,
"Cups per Serving": -1
},
{
"Cereal Name": "Just_Right_Fruit_&_Nut",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 140,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 170,
"Dietary Fiber": 2,
"Carbs": 20,
"Sugars": 9,
"Display Shelf": 3,
"Potassium": 95,
"Vitamins and Minerals": 100,
"Serving Size Weight": 1.3,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Kix",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 260,
"Dietary Fiber": 0,
"Carbs": 21,
"Sugars": 3,
"Display Shelf": 2,
"Potassium": 40,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1.5
},
{
"Cereal Name": "Life",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 100,
"Protein (g)": 4,
"Fat": 2,
"Sodium": 150,
"Dietary Fiber": 2,
"Carbs": 12,
"Sugars": 6,
"Display Shelf": 2,
"Potassium": 95,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Lucky_Charms",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 180,
"Dietary Fiber": 0,
"Carbs": 12,
"Sugars": 12,
"Display Shelf": 2,
"Potassium": 55,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Maypo",
"Manufacturer": "American Home Food Products",
"Type": "H",
"Calories": 100,
"Protein (g)": 4,
"Fat": 1,
"Sodium": 0,
"Dietary Fiber": 0,
"Carbs": 16,
"Sugars": 3,
"Display Shelf": 2,
"Potassium": 95,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": -1
},
{
"Cereal Name": "Mueslix_Crispy_Blend",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 160,
"Protein (g)": 3,
"Fat": 2,
"Sodium": 150,
"Dietary Fiber": 3,
"Carbs": 17,
"Sugars": 13,
"Display Shelf": 3,
"Potassium": 160,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.5,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Multi-Grain_Cheerios",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 100,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 220,
"Dietary Fiber": 2,
"Carbs": 15,
"Sugars": 6,
"Display Shelf": 1,
"Potassium": 90,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Nut&Honey_Crunch",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 120,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 190,
"Dietary Fiber": 0,
"Carbs": 15,
"Sugars": 9,
"Display Shelf": 2,
"Potassium": 40,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Nutri-Grain_Almond-Raisin",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 140,
"Protein (g)": 3,
"Fat": 2,
"Sodium": 220,
"Dietary Fiber": 3,
"Carbs": 21,
"Sugars": 7,
"Display Shelf": 3,
"Potassium": 130,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.33,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Nutri-grain_Wheat",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 90,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 170,
"Dietary Fiber": 3,
"Carbs": 18,
"Sugars": 2,
"Display Shelf": 3,
"Potassium": 90,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": -1
},
{
"Cereal Name": "Oatmeal_Raisin_Crisp",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 130,
"Protein (g)": 3,
"Fat": 2,
"Sodium": 170,
"Dietary Fiber": 1.5,
"Carbs": 13.5,
"Sugars": 10,
"Display Shelf": 3,
"Potassium": 120,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.25,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Post_Nat._Raisin_Bran",
"Manufacturer": "Post",
"Type": "C",
"Calories": 120,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 200,
"Dietary Fiber": 6,
"Carbs": 11,
"Sugars": 14,
"Display Shelf": 3,
"Potassium": 260,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.33,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Product_19",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 320,
"Dietary Fiber": 1,
"Carbs": 20,
"Sugars": 3,
"Display Shelf": 3,
"Potassium": 45,
"Vitamins and Minerals": 100,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Puffed_Rice",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 50,
"Protein (g)": 1,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 0,
"Carbs": 13,
"Sugars": 0,
"Display Shelf": 3,
"Potassium": 15,
"Vitamins and Minerals": 0,
"Serving Size Weight": 0.5,
"Cups per Serving": 1
},
{
"Cereal Name": "Puffed_Wheat",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 50,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 1,
"Carbs": 10,
"Sugars": 0,
"Display Shelf": 3,
"Potassium": 50,
"Vitamins and Minerals": 0,
"Serving Size Weight": 0.5,
"Cups per Serving": -1
},
{
"Cereal Name": "Quaker_Oat_Squares",
"Manufacturer": "Quaker Oats",
"Type": "C",
"Calories": 100,
"Protein (g)": 4,
"Fat": 1,
"Sodium": 135,
"Dietary Fiber": 2,
"Carbs": 14,
"Sugars": 6,
"Display Shelf": 3,
"Potassium": 110,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Quaker_Oatmeal",
"Manufacturer": "Quaker Oats",
"Type": "H",
"Calories": 100,
"Protein (g)": 5,
"Fat": 2,
"Sodium": 0,
"Dietary Fiber": 2.7,
"Carbs": -1,
"Sugars": -1,
"Display Shelf": 1,
"Potassium": 110,
"Vitamins and Minerals": 0,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Raisin_Bran",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 120,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 210,
"Dietary Fiber": 5,
"Carbs": 14,
"Sugars": 12,
"Display Shelf": 2,
"Potassium": 240,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1.33,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Raisin_Nut_Bran",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 2,
"Sodium": 140,
"Dietary Fiber": 2.5,
"Carbs": 10.5,
"Sugars": 8,
"Display Shelf": 3,
"Potassium": 140,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Raisin_Squares",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 90,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 2,
"Carbs": 15,
"Sugars": 6,
"Display Shelf": 3,
"Potassium": 110,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.5
},
{
"Cereal Name": "Rice_Chex",
"Manufacturer": "Ralston Purina",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 0,
"Sodium": 240,
"Dietary Fiber": 0,
"Carbs": 23,
"Sugars": 2,
"Display Shelf": 1,
"Potassium": 30,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1.13
},
{
"Cereal Name": "Rice_Krispies",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 290,
"Dietary Fiber": 0,
"Carbs": 22,
"Sugars": 3,
"Display Shelf": 1,
"Potassium": 35,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Shredded_Wheat",
"Manufacturer": "Nabisco",
"Type": "C",
"Calories": 80,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 3,
"Carbs": 16,
"Sugars": 0,
"Display Shelf": 1,
"Potassium": 95,
"Vitamins and Minerals": 0,
"Serving Size Weight": 0.83,
"Cups per Serving": -1
},
{
"Cereal Name": "Shredded_Wheat_'n'Bran",
"Manufacturer": "Nabisco",
"Type": "C",
"Calories": 90,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 4,
"Carbs": 19,
"Sugars": 0,
"Display Shelf": 1,
"Potassium": 140,
"Vitamins and Minerals": 0,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Shredded_Wheat_spoon_size",
"Manufacturer": "Nabisco",
"Type": "C",
"Calories": 90,
"Protein (g)": 3,
"Fat": 0,
"Sodium": 0,
"Dietary Fiber": 3,
"Carbs": 20,
"Sugars": 0,
"Display Shelf": 1,
"Potassium": 120,
"Vitamins and Minerals": 0,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Smacks",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 70,
"Dietary Fiber": 1,
"Carbs": 9,
"Sugars": 15,
"Display Shelf": 2,
"Potassium": 40,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Special_K",
"Manufacturer": "Kelloggs",
"Type": "C",
"Calories": 110,
"Protein (g)": 6,
"Fat": 0,
"Sodium": 230,
"Dietary Fiber": 1,
"Carbs": 16,
"Sugars": 3,
"Display Shelf": 1,
"Potassium": 55,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Strawberry_Fruit_Wheats",
"Manufacturer": "Nabisco",
"Type": "C",
"Calories": 90,
"Protein (g)": 2,
"Fat": 0,
"Sodium": 15,
"Dietary Fiber": 3,
"Carbs": 15,
"Sugars": 5,
"Display Shelf": 2,
"Potassium": 90,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": -1
},
{
"Cereal Name": "Total_Corn_Flakes",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 200,
"Dietary Fiber": 0,
"Carbs": 21,
"Sugars": 3,
"Display Shelf": 3,
"Potassium": 35,
"Vitamins and Minerals": 100,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Total_Raisin_Bran",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 140,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 190,
"Dietary Fiber": 4,
"Carbs": 15,
"Sugars": 14,
"Display Shelf": 3,
"Potassium": 230,
"Vitamins and Minerals": 100,
"Serving Size Weight": 1.5,
"Cups per Serving": 1
},
{
"Cereal Name": "Total_Whole_Grain",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 200,
"Dietary Fiber": 3,
"Carbs": 16,
"Sugars": 3,
"Display Shelf": 3,
"Potassium": 110,
"Vitamins and Minerals": 100,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Triples",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 250,
"Dietary Fiber": 0,
"Carbs": 21,
"Sugars": 3,
"Display Shelf": 3,
"Potassium": 60,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
},
{
"Cereal Name": "Trix",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 1,
"Fat": 1,
"Sodium": 140,
"Dietary Fiber": 0,
"Carbs": 13,
"Sugars": 12,
"Display Shelf": 2,
"Potassium": 25,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Wheat_Chex",
"Manufacturer": "Ralston Purina",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 230,
"Dietary Fiber": 3,
"Carbs": 17,
"Sugars": 3,
"Display Shelf": 1,
"Potassium": 115,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.67
},
{
"Cereal Name": "Wheaties",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 100,
"Protein (g)": 3,
"Fat": 1,
"Sodium": 200,
"Dietary Fiber": 3,
"Carbs": 17,
"Sugars": 3,
"Display Shelf": 1,
"Potassium": 110,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 1
},
{
"Cereal Name": "Wheaties_Honey_Gold",
"Manufacturer": "General Mills",
"Type": "C",
"Calories": 110,
"Protein (g)": 2,
"Fat": 1,
"Sodium": 200,
"Dietary Fiber": 1,
"Carbs": 16,
"Sugars": 8,
"Display Shelf": 1,
"Potassium": 60,
"Vitamins and Minerals": 25,
"Serving Size Weight": 1,
"Cups per Serving": 0.75
}
];
// change string (from CSV) into number format
data.forEach(function(d) {
d.Calories = +d.Calories;
d["Protein (g)"] = +d["Protein (g)"];
// console.log(d);
});
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(data, xValue)-1, d3.max(data, xValue)+1]);
yScale.domain([d3.min(data, yValue)-1, d3.max(data, yValue)+1]);
// x-axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Calories");
// y-axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Protein (g)");
// draw dots
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", xMap)
.attr("cy", yMap)
.style("fill", function(d) { return color(cValue(d));})
.on("mouseover", function(d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d["Cereal Name"] + "<br/> (" + xValue(d)
+ ", " + yValue(d) + ")")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// draw legend
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// draw legend colored rectangles
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
// draw legend text
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d;})
//});
</script>
</body>
</html>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js