Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Playing with COVID-19 data - Part 6</h1>

<p>When you select a dataset below, it should show a bar chart below that represents the values starting at the beginning of the pandemic.</p>
<div id="app">
	<h2>Dataset</h2>
	<input 
		name="dataPoint" 
		value="totalTestResults" 
		id="totalTestResults"
		type="radio"
		v-model="column">
	<label for="totalTestResults">Total test results</label><br />
	<input 
		name="dataPoint" 
		value="totalTestResultsIncrease" 
		id="totalTestResultsIncrease"
		type="radio"
		v-model="column">
	<label for="totalTestResultsIncrease">Daily increase in total test results</label><br />
	<input 
		name="dataPoint" 
		value="negative" 
		id="negative"
		type="radio"
		v-model="column">
	<label for="negative">Negative results</label><br />
	<input 
		name="dataPoint" 
		value="negativeIncrease" 
		id="negativeIncrease"
		type="radio"
		v-model="column">
	<label for="negativeIncrease">Daily increase in negative results</label><br />
	<input 
		name="dataPoint" 
		value="positive" 
		id="positive"
		type="radio"
		v-model="column">
	<label for="positive">Positive results</label><br />
	<input 
		name="dataPoint" 
		value="positiveIncrease" 
		id="positiveIncrease"
		type="radio"
		v-model="column">
	<label for="positiveIncrease">Daily increase in positive results</label><br />
	<input 
		name="dataPoint" 
		value="hospitalizedCurrently" 
		id="hospitalizedCurrently"
		type="radio"
		v-model="column">
	<label for="hospitalizedCurrently">Hospitalized currently</label><br />
	<input 
		name="dataPoint" 
		value="hospitalizedIncrease" 
		id="hospitalizedIncrease"
		type="radio"
		v-model="column">
	<label for="hospitalizedIncrease">Daily increase in hospitalizations</label><br />
	<input 
		name="dataPoint" 
		value="death" 
		id="death"
		type="radio"
		v-model="column">
	<label for="death">Deaths</label><br />
	<input 
		name="dataPoint" 
		value="deathIncrease" 
		id="deathIncrease"
		type="radio"
		v-model="column">
	<label for="deathIncrease">Daily increase in deaths</label><br />
	
	<h2>Bar Chart</h2>
	<div id="chart"></div>
</div>
              
            
!

CSS

              
                #chart div {
  display: block;
  background: #4285F4;
  height: 2px;
  margin-right: 3px;
}
              
            
!

JS

              
                new Vue({
  el: "#app",
  data() {
    return {
      info: null,
			focus:[],
			column:''
    };
  },
  mounted() {
    // Get the basic info about the blog
    axios
    .get("https://api.covidtracking.com/v1/states/wi/daily.json")
      .then(response=> (this.info = response.data));
  },
	watch: {
    info: function () {
      console.log(this.info);
    },
    column: function () {
      console.log(this.column);
			// Loop over the array and build focus
			for (let i = 0; i < this.info.length; i++) {
				if(this.column == 'totalTestResults'){
					this.focus.push(this.info[i].totalTestResults);
				}
				if(this.column == 'totalTestResultsIncrease'){
					this.focus.push(this.info[i].totalTestResultsIncrease);
				}
				if(this.column == 'negative'){
					this.focus.push(this.info[i].negative);
				}
				if(this.column == 'negativeIncrease'){
					this.focus.push(this.info[i].negativeIncrease);
				}
				if(this.column == 'positive'){
					this.focus.push(this.info[i].positive);
				}
				if(this.column == 'positiveIncrease'){
					this.focus.push(this.info[i].positiveIncrease);
				}
				if(this.column == 'hospitalizedCurrently'){
					this.focus.push(this.info[i].hospitalizedCurrently);
				}
				if(this.column == 'hospitalizedIncrease'){
					this.focus.push(this.info[i].hospitalizedIncrease);
				}
				if(this.column == 'death'){
					this.focus.push(this.info[i].death);
				}
				if(this.column == 'deathIncrease'){
					this.focus.push(this.info[i].deathIncrease);
				}
			}
			// Flip the array so it goes from the beginning to the end
			this.focus.reverse();
			// Update the bar chart
			d3.select('#chart')
				.selectAll("div")
				.data(this.focus)
				.enter()
				.append("div")
				.style("width", (d)=> d + "px")
    }
	}
});
              
            
!
999px

Console