如何在打字稿中使用Highcharts并做出反应

本尼67b

我试图呈现一个图表,任何图表,与在反应和打字稿项目中带有“ Highcharts”的图表无关。

这是index.html中的脚本源:

 <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
        **<script src="https://code.highcharts.com/highcharts.src.js"></script>**
    </head>
    <body>
        <div id="main" style="width:100%;height:100%"></div>
        <!-- Main -->
          <!-- Main -->
    </body>
</html>

这就是即时通讯使用highcharts的方式:

import * as React from "react";
import * as ReactDOM from "react-dom";
import * as Highcharts from "highcharts";

let myChart = Highcharts.chart("main",{
    chart: {
    type: 'bar'
    },
    title: {
    text: 'Fruit Consumption'
    },
    xAxis: {
    categories: ['Apples', 'Bananas', 'Oranges']
    },
    yAxis: {
    title: {
    text: 'Fruit eaten'
    }
    },
    series: [{
    name: 'Jane',
    data: [1, 0, 4]
    }, {
    name: 'John',
    data: [5, 7, 3]
    }]
    });

export default class Home extends React.Component<any, any> {

        render() {
            return (
                <div>
                    {myChart}
                </div>
            )
        }
}

我收到此错误:

高图错误

拜托,有人可以帮忙吗?也许使用打字稿和反应给出一个高图的工作示例。

深3015

错误状态Highcharts已在页面中定义, highcharts不需要脚本标签,请使用npm中的highcharts模块

查看此现场演示

import * as React from "react";
import * as ReactDOM from "react-dom";
import * as Highcharts from "highcharts";

let myChart = Highcharts.chart("main",{
    chart: {
    type: 'bar'
    },
    title: {
    text: 'Fruit Consumption'
    },
    xAxis: {
    categories: ['Apples', 'Bananas', 'Oranges']
    },
    yAxis: {
    title: {
    text: 'Fruit eaten'
    }
    },
    series: [{
    name: 'Jane',
    data: [1, 0, 4]
    }, {
    name: 'John',
    data: [5, 7, 3]
    }]
    });

export default class Home extends React.Component<any, any> {

        render() {
            return (
                <div>
                    {myChart}
                </div>
            )
        }
}

html

 <div id="main" style="width:100%;height:100%"></div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章