-
Notifications
You must be signed in to change notification settings - Fork 326
tutorial
To use the Toast UI Chart you will need to download the chart source and associated libraries. This application is dependent on tui.code-snippet, tui.component-effects and Raphael.js.
There are two ways to download.
Using the Bower, you can download them easily. The downloaded file will be saved in bower_components
directory.
If you want to know more about the Bower, please refer to the http://bower.io/.
bower install tui-chart
Now, let's include the downloaded files.
You can use following sample.
<!-- include libraries -->
<script src="bower_components/tui-code-snippet/code-snippet.min.js"></script>
<script src="bower_components/tui-component-effects/effects.min.js"></script>
<script src="bower_components/raphael/raphael-min.js"></script>
<!-- include chart.min.js -->
<script src="bower_components/tui-chart/dist/chart.min.js"></script>
You can use following sample.
<!-- include application-chart.min.css -->
<link rel="stylesheet" type="text/css" href="bower_components/tui-chart/dist/chart.min.css" />
If you complete the installation, now you can create a chart.
The following example is creating a bar chart. (For a description of options, please see below.)
var container = document.getElementById('container-id'),
data = {
categories: ['cate1', 'cate2', 'cate3'],
series: [
{
name: 'Legend1',
data: [20, 30, 50]
},
{
name: 'Legend2',
data: [40, 40, 60]
},
{
name: 'Legend3',
data: [60, 50, 10]
},
{
name: 'Legend4',
data: [80, 10, 70]
}
]
},
options = {
chart: {
width: 500,
height: 400,
title: 'Chart Title'
},
yAxis: {
title: 'Y Axis Title'
},
xAxis: {
title: 'X Axis Title'
}
};
tui.chart.barChart(container, data, options);
You can create chart without option.
var container = document.getElementById('container-id'),
data = { ... };
tui.chart.barChart(container, data);
Toast UI Chart has three types of data - basic type, combo chart type and pie chart type.
Basic data type is used in bar chart, column chart, line chart and area chart.
var data = {
categories: ['cate1', 'cate2', 'cate3'],
series: [
{
name: 'Legend1',
data: [20, 30, 50]
},
{
name: 'Legend2',
data: [40, 40, 60]
},
{
name: 'Legend3',
data: [60, 50, 10]
},
{
name: 'Legend4',
data: [80, 10, 70]
}
]
};
Combo Chart data type is more complicated.
var data = {
categories: ['cate1', 'cate2', 'cate3'],
series: {
column: [
{
name: 'Legend1',
data: [20, 30, 50]
},
{
name: 'Legend2',
data: [40, 40, 60]
},
{
name: 'Legend3',
data: [60, 50, 10]
},
{
name: 'Legend4',
data: [80, 10, 70]
}
],
line: [
{
name: 'Legend2_1',
data: [1, 2, 3]
}
]
}
};
Pie Chart data type is more simple.
var data = {
series: [
{
name: 'Legend1',
data: 20
},
{
name: 'Legend2',
data: 50
},
{
name: 'Legend3',
data: 60
},
{
name: 'Legend4',
data: 80
},
{
name: 'Legend5',
data: 10
},
{
name: 'Legend6',
data: 30
}
]
};
How to set options are as follows:
var container = document.getElementById('container-id'),
data = { ... },
options: {
chart: {
width: 500,
height: 400,
title: 'Chart Title'
}
yAxis: {
title: 'Y Axis Title'
},
xAxis: {
title: 'X Axis Title'
}
};
tui.chart.barChart(container, data, options);
You can apply design to a chart by using themes.
How to register themes are as follows:
var theme = {
chart: {
background: '#ffffff',
fontFamily: 'Verdana'
},
//...
};
tui.chart.registerTheme('themeName', theme);
If you want to use themes, you need to add the 'theme' option.
//...
var options = {
theme: 'themeName'
};
tui.chart.lineChart(container, data, options);
var data = {...},
chart = tui.chart.barChart(data);
chart.resize({
width: 700,
height: 800
});
var data = {...},
options = {
//...
tooltip: {
align: 'left top',
position: {
left: 10,
top: 10
}
}
},
chart = tui.chart.barChart(data, options);
// Set align option.
chart.setTooltipAlign('center middle');
// Set position option.
chart.setTooltipPosition({
left: 20,
top: 30
});
// Reset align option.
chart.resetTooltipAlign();
// Reset position option.
chart.resetTooltipPosition();
var data = {...},
chart = tui.chart.barChart(data);
chart.on('selectLegend', function(info) {
console.log(info);
});
var data = {...},
chart = tui.chart.barChart(data);
chart.on('selectSeries', function(info) {
console.log(info);
});
chart.on('unselectSeries', function(info) {
console.log(info);
});
var data = {...},
chart = tui.chart.barChart(data);
chart.on('beforeShowTooltip', function(info) {
console.log(info);
});
chart.on('afterShowTooltip', function(info) {
console.log(info);
});
- Chart Guide