Basic usage of roughViz.js
masterTo use the library in an ESM environment, import roughViz. You must provide a container element (e.g., a div with a specific ID) for each chart you create. You can pass data as a JavaScript object or as a URL to a CSV/TSV file.
import roughViz from "rough-viz";
// 1. Create container elements in HTML
// <div id="viz0"></div>
// 2. Initialize a Bar chart from a CSV file
new roughViz.Bar({
element: '#viz0',
data: 'https://raw.githubusercontent.com/jwilber/random_data/master/flavors.csv',
labels: 'flavor',
values: 'price'
});
// 3. Initialize a Donut chart using an object
new roughViz.Donut({
element: '#viz1',
data: {
labels: ['North', 'South', 'East', 'West'],
values: [10, 5, 8, 3]
},
title: "Regions",
roughness: 8,
colors: ['red', 'orange', 'blue', 'skyblue'],
stroke: 'black',
strokeWidth: 3,
fillStyle: 'cross-hatch',
fillWeight: 3.5,
});