VSeed, an elegant data composer, transforming complexity into simplicity.
!!!###!!!title=Quick Start——VisActor/VChart tutorial documents!!!###!!!!!!###!!!description=In this tutorial, we will introduce how to use VChart to draw a simple bar chart. VChart is a simple-to-use, cross-platform, high-performance frontend visualization chart library. Charts are composed of data, series, and components. We will use the configuration options to declare the chart.!!!###!!!
Quick Start
In this tutorial, we will introduce how to use VChart to draw a simple bar chart. VChart is a simple-to-use, cross-platform, high-performance frontend visualization chart library. Charts are composed of data, series, and components. We will use the configuration options to declare the chart.
Getting VChart
You can obtain VChart in the following ways.
Using NPM package
First, you need to install VChart in the project root directory using the following command:
# Install using npmnpm install @visactor/vchart
# Install using yarnyarn add @visactor/vchart
Using CDN
You can also obtain the pre-built VChart file via CDN. Add the following code to the <script> tag in the HTML file:
Before drawing, we need to prepare a DOM container with a width and height for VChart.
<body><!-- Prepare a DOM with size (width and height) for vchart, or you can specify it in the spec configuration --><divid="chart"style="width: 600px;height:400px;"></div></body>
Next, we create a VChart instance, passing in the chart configuration options and the ID of the DOM container:
const spec = {
data: [
{
id: 'barData',
values: [
{ month: 'Monday', sales: 22 },
{ month: 'Tuesday', sales: 13 },
{ month: 'Wednesday', sales: 25 },
{ month: 'Thursday', sales: 29 },
{ month: 'Friday', sales: 38 }
]
}
],
type: 'bar',
xField: 'month',
yField: 'sales'
};
// Create a vchart instance/**
* Note: When using the CDN approach for importing, pay attention to the way VChart is referenced:
* const vchart = new VChart.default(spec, { dom: 'chart' });
*/const vchart = new VChart(spec, { dom: 'chart' });
// Draw the chartvchart.renderSync();
At this point, you have successfully drawn a simple bar chart!
I hope this tutorial has helped you learn how to use VChart. Now, you can try drawing different types of charts and customize more diverse chart effects by delving into the various configuration options available in VChart. Embark on your VChart journey with confidence!