答案 0 :(得分:1)
旋转v4的图表仅是将类别/值轴分配给所需的xAxes / yAxes数组,并将轴的oppsite
的{{1}}和inversed
属性设置为true的问题对象,具体取决于轴。例如:
renderer
演示:
// place category axis on the y axis
// use inversed to reverse the order so
// the first category is on top
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
// ...
categoryAxis.renderer.inversed = true;
// place value axis on the x axis and use the opposite property to move it up top
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
// ...
valueAxis.renderer.opposite = true;
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
chart.data = [{
"country": "USA",
"visits": 3025
}, {
"country": "China",
"visits": 1882
}, {
"country": "Japan",
"visits": 1809
}, {
"country": "Germany",
"visits": 1322
}, {
"country": "UK",
"visits": 1122
}, {
"country": "France",
"visits": 1114
}, {
"country": "India",
"visits": 984
}, {
"country": "Spain",
"visits": 711
}, {
"country": "Netherlands",
"visits": 665
}, {
"country": "Russia",
"visits": 580
}, {
"country": "South Korea",
"visits": 443
}, {
"country": "Canada",
"visits": 441
}];
// place category axis on the y axis
// use inversed to reverse the order so
// the first category is on top
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "country";
categoryAxis.renderer.inversed = true;
// place value axis on the x axis and use the opposite property to move it up top
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
valueAxis.renderer.opposite = true;
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueX = "visits";
series.dataFields.categoryY = "country";
series.tooltipText = "[{categoryX}: bold]{valueY}[/]";
#chartdiv {
width: 95%;
height: 300px;
}