Quantcast
Channel: 簡睿隨筆
Viewing all articles
Browse latest Browse all 897

Obs137|用Dataviewjs讀取CSV資料以繪製統計圖表

$
0
0

Dataviewjs可以用下列3種函數讀取外部檔案:

[!COMMENT]+ Dataviewjs讀檔

  1. 內容 = await dv.io.csv(路徑, [origin-file])
  2. 內容 = await dv.io.load(路徑, [origin-file])
  3. dv.io.normalize(路徑, [origin-file]): 將相對路徑鏈接轉換成絕對路徑

gh|500

1. 原始碼

let data = await dv.io.csv("visit_places.csv");
//data = data.sort(r => r.country);
//dv.table(["Country", "Date", "Days"], data.map(r => [r.country, r.visit_date, r.visit_days])) 

var labels = [];
const sChartColor = '#4e9a06';

const lineChart = {
  type: 'bar',
  width: '50%',
  data: {
    labels: data.country.values,
    datasets: [{
      label: 'Days',
      data: data.visit_days.values,
      backgroundColor: [
        sChartColor
      ],
      borderColor: [
        "white"
      ],
      borderWidth: 1
    }]
  }
}  // lineChart

window.renderChart(lineChart, this.container);

2. 相關鏈接

3. 教學影片

##

您可能也會有興趣的類似文章


Viewing all articles
Browse latest Browse all 897

Trending Articles