旋转 v4 的图表只是将类别/值轴分配给所需的 xAxes/yAxes 数组并将轴的对象中的oppsiteandinversed属性设置为 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;
Run Code Online (Sandbox Code Playgroud)
演示:
// 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;
Run Code Online (Sandbox Code Playgroud)
// 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}[/]";Run Code Online (Sandbox Code Playgroud)
#chartdiv {
width: 95%;
height: 300px;
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1539 次 |
| 最近记录: |