Created
October 17, 2019 23:29
-
-
Save nchibana/3242dbb66ce32144f0dccdb8c6bdec5d to your computer and use it in GitHub Desktop.
d3 update data function
This file contains hidden or 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
| function updateData(){ | |
| d3.json('https://storyplotsapp.herokuapp.com/api', { | |
| method:"POST", | |
| body: JSON.stringify({ | |
| movie_title: ItemSelect | |
| }), | |
| headers: {"Content-type": "application/json; charset=UTF-8"} | |
| }).then(function(data){ | |
| console.log(data); | |
| // // Prepare and clean data | |
| filteredData = {}; | |
| for (var movie in data) { | |
| if (!data.hasOwnProperty(movie)) { | |
| continue; | |
| } | |
| filteredData[movie] = data[movie]; | |
| filteredData[movie].forEach(function(d){ | |
| d["score"] = +d["score"]; | |
| d["percent"] = +d["percent"]; | |
| d["cluster3"] = +d["cluster3"]; | |
| }); | |
| console.log(filteredData); | |
| } | |
| d3.selectAll("svg").remove(); | |
| indexSearch = d3.keys(data).indexOf(ItemSelect); | |
| var indexes = [0,1,2,3,4,5] | |
| new_array = indexes.filter(function checkIndex(index) { | |
| return index !== indexSearch; | |
| }); | |
| console.log(new_array); | |
| lineChart1 = new LineChart("#chart-area1", d3.keys(data)[indexSearch]); | |
| lineChart2 = new LineChart("#chart-area2", d3.keys(data)[new_array[0]]); | |
| lineChart3 = new LineChart("#chart-area3", d3.keys(data)[new_array[1]]); | |
| lineChart4 = new LineChart("#chart-area4", d3.keys(data)[new_array[2]]); | |
| lineChart5 = new LineChart("#chart-area5", d3.keys(data)[new_array[3]]); | |
| lineChart6 = new LineChart("#chart-area6", d3.keys(data)[new_array[4]]); | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment