javascript - 使用 React TypeScript 的 Highcharts 地图
问题描述
我正在尝试使用 TypeScript 编写WorldMap 示例,但我对 Highcharts Options 中的系列有疑问:
(Highcharts, Highstock, Highmaps, Gantt) Series options for specific data and the data itself. In TypeScript you have to cast the series options to specific series types, to get all possible options for a series.
它看起来像series
要求type: 'map'
,但我已经尝试过了,它没有工作。我还在线查看了示例和答案(1、2、3、4),但它们仅适用于jsx
not中的 React tsx
。
import * as React from 'react';
import * as Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import mapDataWorld from '@highcharts/map-collection/custom/world.geo.json';
const options: Highcharts.Options = {
title: {
text: 'My chart'
},
series: [
{
mapData: mapDataWorld,
// data: data,
name: "USA",
dataLabels: {
enabled: true,
format: "{point.name}"
}
}
],
}
export default function HighchartsTest(props: HighchartsReact.Props) {
return (
<div>
<HighchartsReact
highcharts={Highcharts}
options={options}
{...props}
/>
</div>
)
}
解决方案
我在您的尝试中发现了一些问题。
地图模块未导入(在本例中为 highmaps)。
缺少构造函数类型
constructorType={'mapChart'}
这是一个演示:https ://stackblitz.com/edit/react-ts-zs69rw?file=index.tsx
请注意,必须定义类型,并且数据数组也需要定义类型。我认为您的问题是由于缺少模块而发生的。
推荐阅读
- java - 如何使用来自控制台的输入
- python - 如何将重复的数据行排列成一行
- android - 如何在同一活动android中将变量从一种方法传递给另一种方法
- c++ - 为什么字符串比较会导致无限循环
- angularjs - Angular 1.6.1 ng--option 值以 type 为前缀:
- swift - PromiseKit 6、Alamofire、Xcode 10.2/Swift 5
- javascript - 如何在javascript中舍入十进制数
- maya - Mel Button Color ScriptJob?
- knockout.js - 如何使用 KnockoutJs 更改我的语言内容?
- sql - 根据条件获取列的总和