
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import React, { Component } from "react";
import * as am5 from "@amcharts/amcharts5";
import * as am5xy from "@amcharts/amcharts5/xy";
import am5themes_Animated from "@amcharts/amcharts5/themes/Animated";
class Chart extends Component {
componentDidMount() {
let root5 = am5.Root.new("chart");
root5._logo.dispose();
// Set themes
// https://www.amcharts.com/docs/v5/concepts/themes/
root5.setThemes([
am5themes_Animated.new(root5)
]);
// Create chart
// https://www.amcharts.com/docs/v5/charts/xy-chart/
let chart = root5.container.children.push(am5xy.XYChart.new(root5, {
panX: true,
panY: true,
wheelX: "panX",
wheelY: "zoomX",
pinchZoomX:true
}));
// Add cursor
// https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
let cursor = chart.set("cursor", am5xy.XYCursor.new(root5, {}));
cursor.lineY.set("visible", false);
// Create axes
// https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
let xRenderer = am5xy.AxisRendererX.new(root5, { minGridDistance: 30 });
xRenderer.labels.template.setAll({
rotation: -90,
centerY: am5.p50,
centerX: am5.p100,
paddingRight: 15
});
let xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root5, {
maxDeviation: 0.3,
categoryField: "country",
renderer: xRenderer,
tooltip: am5.Tooltip.new(root5, {})
}));
let yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root5, {
maxDeviation: 0.3,
renderer: am5xy.AxisRendererY.new(root5, {})
}));
// Create series
// https://www.amcharts.com/docs/v5/charts/xy-chart/series/
let series = chart.series.push(am5xy.ColumnSeries.new(root5, {
name: "Series 1",
xAxis: xAxis,
yAxis: yAxis,
valueYField: "value",
sequencedInterpolation: true,
categoryXField: "country",
tooltip: am5.Tooltip.new(root5, {
labelText:"{valueY}"
})
}));
series.columns.template.setAll({ cornerRadiusTL: 5, cornerRadiusTR: 5 });
series.columns.template.adapters.add("fill", function(fill, target) {
return chart.get("colors").getIndex(series.columns.indexOf(target));
});
series.columns.template.adapters.add("stroke", function(stroke, target) {
return chart.get("colors").getIndex(series.columns.indexOf(target));
});
// Set data
let data = [{
country: "1주",
value: 80
}, {
country: "2주",
value: 80
}, {
country: "3주",
value: 70
}, {
country: "4주",
value: 80
}];
xAxis.data.setAll(data);
series.data.setAll(data);
// Make stuff animate on load
// https://www.amcharts.com/docs/v5/concepts/animations/
series.appear(1000);
chart.appear(1000, 100);
}
componentWillUnmount() {
if (this.root5) {
this.root5.dispose();
}
}
render() {
return <div id="chart" style={{ width: "100%", height: "90%" }}></div>;
}
}
export default Chart;