有什么方法可以在json中传递多序列数据,因为它在reactjs的anychart中不能正常工作吗?

问题描述

我正在尝试在React中使用AnyChart来实现柱形图,并且正在以JSON传递多序列数据,但是它不能正常工作,这是一个简单的JSON结构,我需要知道如何在react中传递多序列数据。 / p>

from ib_insync import * 
from concurrent.futures import ThreadPoolExecutor 
import random 
import nest_asyncio 
nest_asyncio.apply()
    
# Define IB object 
ib = IB()
    
# Connect to IB 
ib.connect('127.0.0.1',7497,clientId=131)
    
# Define sample function with ib.sleep 
def sample_function(sleep_time):
    print('Sleeping Now') 
    ib.sleep(sleep_time)
    print('Sleep completed!')
    
# Call function directly - works fine
sample_function()
    
# Run multiple threads and call function within each thread - RunTimeWarning and stops
executor = ThreadPoolExecutor(max_workers=2) 
executor.submit(sample_function,random.randint(1,20)) 
executor.submit(sample_function,20))

解决方法

是的,此特定格式不支持多系列数据。为此,我们建议使用其他方法:

import React from 'react'
import ReactDOM from 'react-dom'
import AnyChart from '../../dist/anychart-react.min.js'
import anychart from 'anychart'

const data = anychart.data.set([
  ['p1',5,4],['p2',6,2],['p3',3,7],['p4',1,5]
]);

// Render chart with settings
ReactDOM.render(<AnyChart type="column" title="Multicolumn chart" width={800} height={600} legend={true} />,document.getElementById('root'));
// Re-render with multicolumn data. No need to set type secondly,because it just updates data
ReactDOM.render(<AnyChart data={data}/>,document.getElementById('root'));

或使用实例字段,这是使用插件最灵活的方式:

import React from 'react'
import ReactDOM from 'react-dom'
import AnyChart from '../../dist/anychart-react.min.js'
import anychart from 'anychart'

  const data = anychart.data.set([
    ['p1',5]
  ]);

  var mapping1 = data.mapAs({x: 0,value: 1});
  var mapping2 = data.mapAs({x: 0,value: 2});

  const chart = anychart.column();

  chart.column(mapping1);
  chart.column(mapping2);

ReactDOM.render(
  <AnyChart
    width={800}
    height={600}
    instance={chart}
    title="Stock demo"
  />,document.getElementById('root'));

有关详细信息,请检查the plugin page上的示例。