FusionCharts未在React中更新

时间:2016-11-16 20:08:49

标签: javascript reactjs fusioncharts

尝试使用the sample given by FusionCharts更新React中的图表时,我无法让图表更新。它肯定会改变这个值,我通过添加这一行找到了它:

console.log(revenueChartConfigs.dataSource.data[2].value);

根据需要,该值从590000更改为420000,但图表不会更新。有没有人对此提出建议?我在下面粘贴了我的代码。感谢。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript" src="js/fusioncharts.js"></script>
    <script type="text/javascript" src="js/fusioncharts.charts.js"></script>
    <script type="text/javascript" src="js/fusioncharts.gantt.js"></script>
    <script type="text/javascript" src="js/fusioncharts.maps.js"></script>
    <script type="text/javascript" src="js/fusioncharts.powercharts.js"></script>
    <script type="text/javascript" src="js/fusioncharts.ssgrid.js"></script>
    <script type="text/javascript" src="js/fusioncharts.treemap.js"></script>
    <script type="text/javascript" src="js/fusioncharts.widgets.js"></script>
    <script type="text/javascript" src="js/fusioncharts.zoomscatter.js"></script>
    <script src="https://unpkg.com/react@15/dist/react.js"></script>
    <script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/react-fusioncharts.min.js"></script>
    <script type='text/babel'>
    $(document).ready(function(){
      var myDataSource = {
      chart: {
          caption: "Top 5 stores in last month by revenue",
          subCaption: "Harry's SuperMart",
          numberPrefix: "$",
          theme: "fint"
      },
      data: [{
          label: "Bakersfield Central",
          value: "880000"
      }, {
          label: "Garden Groove harbour",
          value: "730000"
      }, {
          label: "Los Angeles Topanga",
          value: "590000"
      }, {
          label: "Compton-Rancho Dom",
          value: "520000"
      }, {
          label: "Daly City Serramonte",
          value: "330000"
      }]
      };

      var RevenueChart = React.createClass({
      /**
      ** `getInitialState()` method is used to initialize the state of the
      ** the `RevenueChart` component.
      **/
      getInitialState: function () {
          return {
              eventTarget: ''
          };
      },

      /**
      ** The `handleClick()` function is defined in the `RevenueChart` component.
      ** This function is configured to store the state of the `eventTarget` using
      ** the `setState()` method of React. This is binded to button click.
      **/
      handleCLick: function () {
          this.setState({
              eventTarget: 'btn-update-data'
          });
      },

      render: function () {
          var revenueChartConfigs = {
              id: "revenue-chart",
              renderAt: "revenue-chart-container",
              type: "column2d",
              width:600,
              height: 400,
              dataFormat: "json",
              dataSource: myDataSource,
              eventTarget: this.state.eventTarget,
              impactedBy: ['btn-update-data']
          };

          /**
          ** Using the state, we update the `label` and `value` for the third and
          ** fourth data plots in the `render()` method of RevenueChart. The configuration
          ** object that is passed as props is used to refer to the `label`
          ** and `value` attributes of the `data` object array.
          **/
          if (this.state.eventTarget && this.state.eventTarget.length != 0) {
              revenueChartConfigs.dataSource.data[2].label = "Art Supply Store";
              revenueChartConfigs.dataSource.data[2].value = "420000";
              revenueChartConfigs.dataSource.data[3].label = "P.C. Richard & Son";
              revenueChartConfigs.dataSource.data[3].value = "320000";
          }
          else {
              revenueChartConfigs.dataSource = myDataSource;
          }
          console.log(revenueChartConfigs.dataSource.data[2].value);

          return (
              <div>
                /** The `FusionCharts` React component is used to render the chart. **/
                  <react_fc.FusionCharts {...revenueChartConfigs} />

                  /** Create a button, which when clicked will call the `handleClick()` function. **/
                  <a  id='btn-update-data'
                      onClick={this.handleCLick}
                      className="btn btn-default"
                      href="#">{'Click me to change data'}</a>
              </div>
          );
      }
      });
      ReactDOM.render(
        <RevenueChart />,
        document.getElementById('chart-container')
      );
    });
    </script>
  </head>
  <body>
  Hello
  <div id="chart-container"></div>
  </body>
</html>

0 个答案:

没有答案