score:1
i've made some adjustments to your code to make it work.
- first, i moved all the scripts tags to the end of the
<body>
tag and placed them in order. - second, i added
d3-fetch.js
as a dependency and removed the duplicatedd3.js
one. - third, i disabled all the auto update code in order to test the code and avoid becoming insane.
when i opened the html file with my browser without using a web server, the request for the file failed so the code didn't work.
i installed live server
in vscode and it started to work immediately, being able to read the file and append elements to the body.
another error i had was uncaught typeerror: document.getelementsbytagname(...)[totalimages] is undefined
as it could read the data. once i could open the file, that error disappeared.
<html>
<head>
<style>
body {
box-sizing: border-box;
}
.matches {
text-align:center;
float: left;
width: 355px;
border: 1px solid white;
border-collapse: collapse;
}
.column {
text-align:center;
float: left;
width: 355px;
border: 1px solid white;
border-collapse: collapse;
}
.grid {
float: left;
width: 1431px;
}
.row:after {
content: "";
display: table;
clear: both;
}
.button {
background-color: #33ccff;
color: black;
font-weight: bold;
}
input[type=submit] {
background-color: #33ccff;
color: black;
font-weight: bold;
}
html {
overflow: scroll;
overflow-x: hidden;
}
::-webkit-scrollbar {
width: 0px; /* remove scrollbar space /
background: transparent; / optional: just make scrollbar invisible /
}
/ optional: show position indicator in red */
::-webkit-scrollbar-thumb {
background: #ff0000;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.1.1/d3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-fetch@3"></script>
</head>
<body style="background-color:black;">
<div style="color:white;font-weight:bold;overflow:hidden;overflow-y:scroll;" class="grid games" id="lista-de-jogos-lateral">
</div>
<script id="script-da-caixa-de-selecao-suspensa-5">
var select_5 = d3.select("#lista-de-jogos-lateral")
.append("div")
.attr("id","select-box-5")
.style("width","100%")
.style("max-height","574px");
async function update() {
let data = await d3.csv("./lista_de_jogos.csv");
console.log("data from csv file: ", {data})
let update_5 = select_5.selectall(".matches")
.data(data,d=>d.label);
update_5.exit().remove();
// enter new divs:
const enter = update_5.enter()
.append("div")
.attr("class","matches")
// append the children to entered divs:
enter.append("form")
.attr("action",d => d.market)
.attr("target","_blank")
.style("width","100%")
.append("input")
.attr("type","submit")
.attr("target","_blank")
.style("width","100%")
.attr("value","jogo betfair");
enter.append("form")
.append("input")
.attr("type","text")
.attr("id",d => "barra-de-texto-para-grafico-" + d.numbergame)
.style("width","100%")
.attr("value", d=>d.label);
enter.append("img")
.attr("type","text")
.attr("src","https://sitedeapostas-com.imgix.net/assets/local/company/logos/betfair_logo_transp.png?auto=compress%2cformat&fit=clip&q=75&w=263&s=c1691b4034fd0c4526d27ffe8b1e839c")
.attr("name",d => "grafico-betfair-" + d.numbergame);
}
update();
console.log("auto csv update is disabled!")
//setinterval(update,2000);
</script>
<script id="auto-update-images">
let interval_images
window.addeventlistener('domcontentloaded', () => {
console.log("auto update images is disabled!")
interval_images = refresh_images(); //setinterval(refresh_images, 5000); // refresh every 5 sec
})
function refresh_images() {
if (!document.images) return;
const totalimages = document.queryselectorall("img").length - 1;
const lastimages = parseint(document.getelementsbytagname('img')[totalimages].getattribute('name').replace("grafico-betfair-", "")) + 1;
for (let i = 1; i < lastimages; i++) {
try {
document.images['grafico-betfair-' + i].src = document.getelementbyid('barra-de-texto-para-grafico-' + i).value;
} catch (e) {
}
}
}
</script>
<script id="random-number">
function generaterandomintegerinrange(min, max) {
return math.floor(math.random() * (max - min + 1)) + min;
}
</script>
</body>
</html>
if you try to run this code with the "run code snippet" button, it will fail as it doesn't have access to the csv file. it should work with valid data, though. your code is expecting to replace the images url by using a field available in the csv file so make sure your data has those fields.
Source: stackoverflow.com
Related Query
- How to update data on a page according to data from a CSV file instead of using fixed element data on the page?
- How to update elements of an HTML that the elements are created using data from a CSV file?
- How to load data from a CSV file in D3 v5
- display data from csv file into BarGraph using d3.js
- how to update data form file json using d3.js (zoomable circle pack)
- How to fetch data from json file to draw a dynamic graph by using d3.js
- In a d3 scatterplot using data from a csv file, how do i draw lines connecting related points when the mouse is over a point?
- Using hardcoded data instead of CSV file in D3 graphs
- How to make a scatter plot from a CSV file using d3.js?
- How to plot histograms using d3.js from text file instead of random generation using map
- D3.js using data from csv file to populate svg map
- how to transpose data from csv file in d3.js
- How to create a multiseries line chart using data filtered from a csv file?
- How do I retrieve an array from a csv file in javascript using d3?
- How to plot data to map from csv file in D3.js
- getting and using data from CSV file d3 v5
- How should i access specific data from large JSON file using a search button?
- How to sort number columns from csv file read in using D3.js - columns read in as strings
- using variable to parse data with D3js when reading in from csv file
- How to extract data from a csv file and create a line chart from it in D3.js
- unable to read data from a CSV file using javascript
- how to plot data from JSON object on .svg file using D3.js
- D3js take data from an array instead of a file
- d3 - reading JSON data instead of CSV file
- Cannot import data from csv file in d3
- d3.js filter from csv file using multiple columns
- How to load data from an internal JSON array rather than from an external resource / file for a collapsible tree in d3.js?
- How do I read a CSV file into an array using d3js v5
- how to get data with tsv or csv to array in d3.js from a txt file?
- How would I import a single column CSV file into a pie chart using Javascript D3?
More Query from same tag
- tool tip for half donut or half pie chart
- D3 chart with JSON web service
- Embedding csv in HTML for use with D3.js
- D3 bar chart from objects with arrays
- d3 vertical bar chart
- Using D3 Charts in Apache Zeppelin
- d3.js not understanding svg:path
- D3 Collapsible Force Layout Mixing up Children and Parents
- d3.tsv to load tsv file not working
- Why does D3 not insert elements inside the selected element, when using data().enter()?
- How to add day numbers to D3 calendar heatmap?
- D3 Library — How To Access Data from JSON in this example
- Make the y-axis fixed irrespective of the content of the chart
- D3.js zoom is not working with mousewheel in safari
- Queue of transitions in d3.js; one by one
- show data of each circle of bubble chart in table d3.js
- Using d3 to shade area between two lines
- How to get all overlapping elements on 'mouseenter' in D3?
- d3 path d = MNaN,NaNLNaN,NaN
- filter the json data and draw the nvd3 chart using filtered data
- reusable Bar chart showing bars one over another which have same names
- Venn Diagram with d3js
- How do I position a text on top of a circle?
- D3 tooltip error: "Cannot read property '-1' of undefined"
- d3 drag blurring/jittery handle
- How does d3.js decides how many and which ticks to show?
- D3 - flare not showing all data
- Center d3.js JavaScript Plot
- Angular directive async data not binding?
- Date parsing troubles with javascript and regex