gpt4 book ai didi

asp.net-mvc - 将 Morris.js 与 reactjs 结合使用

转载 作者:行者123 更新时间:2023-12-04 02:06:40 26 4
gpt4 key购买 nike

如何使用 reactjs 创建 morris.js 图表?
我正在使用带有 react.js 库的 Asp.net MVC5 项目。这是我的第一个 react 项目,我想在单击某个按钮时更改 morris.js 图表。
我不想在 react js 脚本中使用其他 react 库只是 morris js librayr

最佳答案

以下是让 Morris.js 与 React 一起工作的方法。

  • 安装 Morris.js 及其依赖项 - Raphael.js:
  • npm install --save-dev morris.js
    npm install --save-dev raphael
  • 在您的组件中:
  • import Raphael from 'raphael';
    import 'morris.js/morris.css';
    import 'morris.js/morris.js';
  • 莫里斯希望拉斐尔在全局范围内工作
  • constructor() {
    super();
    window.Raphael = Raphael;
    }

    重要笔记
  • 如果您收到 morris.css 的编译错误,请阅读 this .
  • 如果你写 import Morris from 'morris.js/morris.js' ,它不会工作。
  • 还有另一种方法可以让 Raphael 处于全局范围内。
  • const webpack = require('webpack');
    module.exports = {
    plugins: [
    new webpack.ProvidePlugin({
    Raphael: 'raphael'
    })
    ],
    ...
    }

    如果您更喜欢此变体,则不需要:
    import Raphael from 'raphael';
    window.Raphael = Raphael;

    关于asp.net-mvc - 将 Morris.js 与 reactjs 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42813152/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com