somonus / react-native-echarts

Echarts for react-native. The react-naitve chart.
MIT License
722 stars 309 forks source link

setNewOption会导致横坐标有些label不显示 #100

Open chj-damon opened 6 years ago

chj-damon commented 6 years ago
export default class Demo1 extends React.PureComponent {
  constructor() {
    super();
    this.state = {
      option: {
        title: {
          text: 'ECharts demo'
        },
        tooltip: {},
        legend: {
          data: ['销量']
        },
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10]
          }
        ]
      }
    };
  }

  componentWillReceiveProps(nextProps) {
    console.log(nextProps.data.xAxis, nextProps.data.data);
    this.chart.setNewOption({
      title: {
        text: 'ECharts demo'
      },
      tooltip: {},
      legend: {
        data: ['销量']
      },
      xAxis: {
        data: nextProps.data.xAxis
      },
      series: [
        {
          name: '销量',
          type: 'bar',
          data: nextProps.data.data
        }
      ]
    });
  }

  render() {
    return (
      <Card title="历史销售金额(月)">
        <Echarts
          option={this.state.option}
          height={300}
          ref={chart => (this.chart = chart)}
        />
      </Card>
    );
  }
}

后台接口返回的数据是:

"xAxis": ["衬衫1", "羊毛衫1", "雪纺衫1", "裤子", "高跟鞋", "袜子"],
"data": [5, 20, 36, 10, 10, 20]

会发现,重绘后的柱状图的横坐标上面有一些label没有显示出来。 请问这个应该是什么问题呢?