javascript - amcharts 如何在地图上放置实心仪表
问题描述
我有点坚持尝试将带有动态饼图(https://www.amcharts.com/demos/map-dynamic-pie-charts/)的地图演示转换为具有相同的地图,但将饼图替换为实心量规 ( https://www.amcharts.com/demos/solid-gauge/ )。
以下是我试图将饼图模板转换为雷达图的代码草稿,但我收到一条错误消息:
TypeError:无法读取未定义的属性“xAxes”
也
错误:属性 d:预期数字,“MNaN,NaN L-9.333…”。
我过去使用过其他工作示例,并且能够结合两个示例来获得我需要的设计,但是在多次尝试了解我在这里做错了什么或缺少什么之后,我真的很挣扎?谁能指出我正确的方向?
<!-- Styles -->
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/maps.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<script src="https://cdn.amcharts.com/lib/4/geodata/continentsLow.js"></script>
<!-- Chart code -->
<script>
am4core.ready(function() {
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
var mapChart = am4core.create("chartdiv", am4maps.MapChart);
mapChart.geodata = am4geodata_continentsLow;
mapChart.projection = new am4maps.projections.Miller;
mapChart.seriesContainer.draggable = true;
mapChart.seriesContainer.resizable = true;
mapChart.minZoomLevel = 1;
mapChart.maxZoomLevel = 2000;
// countries
var wholeWorld = mapChart.series.push(new am4maps.MapPolygonSeries());
wholeWorld.exclude = ['AQ'];
wholeWorld.useGeodata = true;
wholeWorld.mapPolygons.template.fill = am4core.color("#47c78a");
wholeWorld.mapPolygons.template.stroke = am4core.color("#cccccc");
// Create an image series that will hold pie charts
var pieSeries = mapChart.series.push(new am4maps.MapImageSeries());
var pieTemplate = pieSeries.mapImages.template;
pieTemplate.propertyFields.latitude = "latitude";
pieTemplate.propertyFields.longitude = "longitude";
var pieChartTemplate = pieTemplate.createChild(am4charts.RadarChart);
pieChartTemplate.adapter.add("data", function(data, target) {
if (target.dataItem) {
return target.dataItem.dataContext.pieData;
} else {
return [];
}
});
// Make chart not full circle
pieChartTemplate.startAngle = -90;
pieChartTemplate.endAngle = 180;
pieChartTemplate.innerRadius = am4core.percent(20);
// Set number format
pieChartTemplate.numberFormatter.numberFormat = "#.#'%'";
pieChartTemplate.propertyFields.width = "width";
pieChartTemplate.propertyFields.height = "height";
pieChartTemplate.horizontalCenter = "middle";
pieChartTemplate.verticalCenter = "middle";
var pieTitle = pieChartTemplate.titles.create();
pieTitle.text = "{title}";
// Create axes
var categoryAxis = pieChartTemplate.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.grid.template.strokeOpacity = 0;
categoryAxis.renderer.labels.template.horizontalCenter = "right";
categoryAxis.renderer.labels.template.fontWeight = 500;
categoryAxis.renderer.labels.template.adapter.add("fill", function(fill, target) {
return (target.dataItem.index >= 0) ? pieChartTemplate.colors.getIndex(target.dataItem.index) : fill;
});
categoryAxis.renderer.minGridDistance = 10;
var valueAxis = pieChartTemplate.xAxes.push(new am4charts.ValueAxis());
valueAxis.renderer.grid.template.strokeOpacity = 0;
valueAxis.min = 0;
valueAxis.max = 100;
valueAxis.strictMinMax = true;
// Create series
var series1 = pieChartTemplate.series.push(new am4charts.RadarColumnSeries());
series1.dataFields.valueX = "full";
series1.dataFields.categoryY = "category";
series1.clustered = false;
series1.columns.template.fill = new am4core.InterfaceColorSet().getFor("alternativeBackground");
series1.columns.template.fillOpacity = 0.08;
series1.columns.template.cornerRadiusTopLeft = 20;
series1.columns.template.strokeWidth = 0;
series1.columns.template.radarColumn.cornerRadius = 20;
var series2 = pieChartTemplate.series.push(new am4charts.RadarColumnSeries());
series2.dataFields.valueX = "value";
series2.dataFields.categoryY = "category";
series2.clustered = false;
series2.columns.template.strokeWidth = 0;
series2.columns.template.tooltipText = "{category}: [bold]{value}[/]";
series2.columns.template.radarColumn.cornerRadius = 20;
series2.columns.template.adapter.add("fill", function(fill, target) {
return pieChartTemplate.colors.getIndex(target.dataItem.index);
});
pieSeries.data = [{
"title": "North America",
"latitude": 39.563353,
"longitude": -99.316406,
"width": 100,
"height": 100,
"pieData": [{
"category": "Research",
"value": 80,
"full": 100
}, {
"category": "Marketing",
"value": 35,
"full": 100
}, {
"category": "Distribution",
"value": 92,
"full": 100
}, {
"category": "Human Resources",
"value": 68,
"full": 100
}]
}, {
"title": "Europe",
"latitude": 50.896104,
"longitude": 19.160156,
"width": 50,
"height": 50,
"pieData": [{
"category": "Research",
"value": 80,
"full": 100
}, {
"category": "Marketing",
"value": 35,
"full": 100
}, {
"category": "Distribution",
"value": 92,
"full": 100
}, {
"category": "Human Resources",
"value": 68,
"full": 100
}]
}, {
"title": "Asia",
"latitude": 47.212106,
"longitude": 103.183594,
"width": 80,
"height": 80,
"pieData": [{
"category": "Research",
"value": 80,
"full": 100
}, {
"category": "Marketing",
"value": 35,
"full": 100
}, {
"category": "Distribution",
"value": 92,
"full": 100
}, {
"category": "Human Resources",
"value": 68,
"full": 100
}]
}, {
"title": "Africa",
"latitude": 11.081385,
"longitude": 21.621094,
"width": 50,
"height": 50,
"pieData": [{
"category": "Research",
"value": 80,
"full": 100
}, {
"category": "Marketing",
"value": 35,
"full": 100
}, {
"category": "Distribution",
"value": 92,
"full": 100
}, {
"category": "Human Resources",
"value": 68,
"full": 100
}]
}];
// Add cursor
pieChartTemplate.cursor = new am4charts.RadarCursor();
}); // end am4core.ready()
</script>
<!-- HTML -->
<div id="chartdiv"></div>
解决方案
这是在 amCharts 4.10.1 版本中修复的错误 - 一旦向他们突出显示,他们很快就解决了。
推荐阅读
- android - 将图像作为意图传递给其他活动中的自定义标记
- selenium - 在python中以无头模式使用selenium webdriver通过Chrome文件上传对话框上传文件
- delphi - 新记录的 Delphi Master Detail 级联 ID 不能与 AutoGenerateValue 结合使用
- vue.js - 在没有 npm install 或 webpack 的情况下导入 vuejs 组件
- json - Codable 函数有什么问题?
- paypal - 贝宝专业 + 红衣主教。在哪里可以找到测试凭证?
- oauth-2.0 - {"error":"invalid_client","message":"客户端认证失败"}
- laravel - JWTAuth::fromUser($newRegistredUser) 给我当前登录用户的令牌
- c++ - 什么是 Linux 等效的 Visual Studio 的“发布模式下的构建代码”?
- apache-kafka - 我想通过一次又一次地调用它来制作一个小数据流