@aniya.jaskolski
To load a CSV file with Vue.js and D3.js, you can use the following steps:
1
|
npm install d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<template> <div> <h1>Data from CSV file:</h1> <ul> <li v-for="item in data" :key="item.id">{{ item.name }}</li> </ul> </div> </template> <script> import * as d3 from 'd3'; export default { data() { return { data: [], }; }, mounted() { d3.csv('data.csv').then((data) => { this.data = data; }); }, }; </script> |
In this example, we import D3.js and use the d3.csv()
method to load a CSV file named data.csv
. Once the data is loaded, we assign it to the data
property of the component.
1 2 3 4 5 |
id,name 1,John 2,Jane 3,Alice 4,Bob |
That's it! You have now successfully loaded a CSV file with Vue.js and D3.js.