首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用React 0.13.3和react-highcharts 3.0.0的Nodata消息

使用React 0.13.3和react-highcharts 3.0.0的Nodata消息
EN

Stack Overflow用户
提问于 2016-05-28 15:20:50
回答 4查看 2.2K关注 0票数 0

我正在与react-highcharts合作。除了无数据状态之外,它工作得很好。当图表有空数据时,我需要显示'No data available‘消息。

我有官方highcharts的check - no-data-to-display.js,但它不能与React一起工作。我想要产生这样的结果:http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/no-data-to-display/no-data-pie/

代码语言:javascript
复制
import React from 'react';
import Highcharts from 'react-highcharts/dist/bundle/highcharts';
require('highcharts-no-data-to-display');

class MyChart extends React.Component {
    constructor(props) {
        super();
        this.state = this._getInitialState(props);
    }
    static chartColors() {
        return [
        '#04a5af', '#4a6cb4', '#2d4665', '#76b5db', '#b4dcee','#cae9de','#24a9b2','#48d0ae','#2a2b32', '#5065ae'
        ]
    }

    componentWillReceiveProps(newProps) {
        this.setState(this._getInitialState(newProps));
    }

    _getInitialState(props) {
        return {
            chartConfig:
            {
                colors: MyChart.chartColors(),
                chart: {
                    type: 'column',
                    events: {
                        load: function(event) {
                            event.target.reflow();
                        }
                    }
                },
                credits: {
                    enabled: false
                },
                title: {
                    text: props.title
                },
                xAxis: {
                    type: 'datetime',
                    title: {
                        text: '',
                        style: {
                            fontSize: '12px'
                        }
                    },
                    labels:{
                        style:{
                            fontSize: '12px'
                        }
                    },
                    dateTimeLabelFormats : {
                        second : '%H:%M',
                        minute : '%H:%M',
                        hour : '%H:%M',
                        day : '%e-$b-%y',
                        week : '%e',
                        month : '%e',
                        year : '%e'
                    },
                    alternateGridColor: '#FAFAFA',
                    startOnTick: true,
                    endOnTick: true,
                    categories: [],
                },
                yAxis: {
                    min: 0,
                    title: {
                        text: props.yTitle?props.yTitle: ""
                    },
                    stackLabels: {
                        enabled: false,
                        style: {
                            fontWeight: 'bold',
                            color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                        }
                    }
                },
                legend: {
                    align: 'center',
                    y: 15,
                    floating: false,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
                    shadow: false
                },
                tooltip: {
                    pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
                },
                plotOptions: {
                    column: {
                        stacking: 'normal',
                        dataLabels: {
                            enabled: false,
                            color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                            style: {
                                textShadow: '0 0 3px black'
                            }
                        }
                    }
                },
                noData: {
                        position: {
                            "x": 0,
                            "y": 0,
                            "align": "center",
                            "verticalAlign": "middle"
                        }
                },
                series: props.series


            }

        };

    }



    render() {


        return (
            <div refs="wa-chart">
                <Highcharts config={this.state.chartConfig} ref="chart" isPureConfig={true} />
            </div>);
    }
}



export default MyChart;

我使用的是react 0.13.3、react-highcharts版本3.0.0和highcharts-no-data-to-display版本0.1.2

EN

回答 4

Stack Overflow用户

发布于 2018-11-09 18:40:54

您的导入应该如下所示。

代码语言:javascript
复制
import Highcharts from 'highcharts';
import NoDataToDisplay from 'highcharts/modules/no-data-to-display';
import HighchartsReact from 'highcharts-react-official';

NoDataToDisplay(Highcharts);

定义要发送noData消息的选项。

代码语言:javascript
复制
const options = {
lang: {
      noData: props.noDataMessage,
    },
    noData: {
      style: {
        fontWeight: 'bold',
        fontSize: '15px',
        color: '#303030',
      },
    },
};

在highcharts中使用此选项。

代码语言:javascript
复制
<HighchartsReact
   highcharts={Highcharts}
   options={options}
/>
票数 1
EN

Stack Overflow用户

发布于 2016-07-14 16:32:20

https://github.com/kirjs/react-highcharts

提示:使用highcharts模块/附加组件,如导出、数据等(演示)

例如:

代码语言:javascript
复制
import React from 'react';
import Highcharts from 'react-highcharts/dist/bundle/highcharts';
require('highcharts-no-data-to-display')(ReactHighcharts.Highcharts)

class MyChart extends React.Component {
    constructor(props) {
        super();
        this.state = this._getInitialState(props);
    }
    static chartColors() {
        return [
        '#04a5af', '#4a6cb4', '#2d4665', '#76b5db', '#b4dcee','#cae9de','#24a9b2','#48d0ae','#2a2b32', '#5065ae'
        ]
    }

    componentWillReceiveProps(newProps) {
        this.setState(this._getInitialState(newProps));
    }

    _getInitialState(props) {
        return {
            chartConfig:
            {
                colors: MyChart.chartColors(),
                chart: {
                    type: 'column',
                    events: {
                        load: function(event) {
                            event.target.reflow();
                        }
                    }
                },
                credits: {
                    enabled: false
                },
                title: {
                    text: props.title
                },
                xAxis: {
                    type: 'datetime',
                    title: {
                        text: '',
                        style: {
                            fontSize: '12px'
                        }
                    },
                    labels:{
                        style:{
                            fontSize: '12px'
                        }
                    },
                    dateTimeLabelFormats : {
                        second : '%H:%M',
                        minute : '%H:%M',
                        hour : '%H:%M',
                        day : '%e-$b-%y',
                        week : '%e',
                        month : '%e',
                        year : '%e'
                    },
                    alternateGridColor: '#FAFAFA',
                    startOnTick: true,
                    endOnTick: true,
                    categories: [],
                },
                yAxis: {
                    min: 0,
                    title: {
                        text: props.yTitle?props.yTitle: ""
                    },
                    stackLabels: {
                        enabled: false,
                        style: {
                            fontWeight: 'bold',
                            color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                        }
                    }
                },
                legend: {
                    align: 'center',
                    y: 15,
                    floating: false,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
                    shadow: false
                },
                tooltip: {
                    pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
                },
                plotOptions: {
                    column: {
                        stacking: 'normal',
                        dataLabels: {
                            enabled: false,
                            color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                            style: {
                                textShadow: '0 0 3px black'
                            }
                        }
                    }
                },
                lang:{
                  noData: 'no data!'
                },
                noData: {
                        position: {
                            "x": 0,
                            "y": 0,
                            "align": "center",
                            "verticalAlign": "middle"
                        }
                },
                series: props.series


            }

        };

    }



    render() {


        return (
            <div refs="wa-chart">
                <Highcharts config={this.state.chartConfig} ref="chart" isPureConfig={true} />
            </div>);
    }
}



export default MyChart;

票数 0
EN

Stack Overflow用户

发布于 2016-07-15 10:17:35

代码语言:javascript
复制
import React from 'react';
import Highcharts from 'react-highcharts/dist/bundle/highcharts';
require('highcharts-no-data-to-display')(Highcharts.Highcharts)

class MyChart extends React.Component {
    constructor(props) {
        super();
        this.state = this._getInitialState(props);
    }
    static chartColors() {
        return [
        '#04a5af', '#4a6cb4', '#2d4665', '#76b5db', '#b4dcee','#cae9de','#24a9b2','#48d0ae','#2a2b32', '#5065ae'
        ]
    }

    componentWillReceiveProps(newProps) {
        this.setState(this._getInitialState(newProps));
    }

    _getInitialState(props) {
        return {
            chartConfig:
            {
                colors: MyChart.chartColors(),
                chart: {
                    type: 'column',
                    events: {
                        load: function(event) {
                            event.target.reflow();
                        }
                    }
                },
                credits: {
                    enabled: false
                },
                title: {
                    text: props.title
                },
                xAxis: {
                    type: 'datetime',
                    title: {
                        text: '',
                        style: {
                            fontSize: '12px'
                        }
                    },
                    labels:{
                        style:{
                            fontSize: '12px'
                        }
                    },
                    dateTimeLabelFormats : {
                        second : '%H:%M',
                        minute : '%H:%M',
                        hour : '%H:%M',
                        day : '%e-$b-%y',
                        week : '%e',
                        month : '%e',
                        year : '%e'
                    },
                    alternateGridColor: '#FAFAFA',
                    startOnTick: true,
                    endOnTick: true,
                    categories: [],
                },
                yAxis: {
                    min: 0,
                    title: {
                        text: props.yTitle?props.yTitle: ""
                    },
                    stackLabels: {
                        enabled: false,
                        style: {
                            fontWeight: 'bold',
                            color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                        }
                    }
                },
                legend: {
                    align: 'center',
                    y: 15,
                    floating: false,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
                    shadow: false
                },
                tooltip: {
                    pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
                },
                plotOptions: {
                    column: {
                        stacking: 'normal',
                        dataLabels: {
                            enabled: false,
                            color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                            style: {
                                textShadow: '0 0 3px black'
                            }
                        }
                    }
                },
                lang:{
                  noData: 'no data!'
                },
                noData: {
                        position: {
                            "x": 0,
                            "y": 0,
                            "align": "center",
                            "verticalAlign": "middle"
                        }
                },
                series: props.series


            }

        };

    }



    render() {


        return (
            <div refs="wa-chart">
                <Highcharts config={this.state.chartConfig} ref="chart" isPureConfig={true} />
            </div>);
    }
}



export default MyChart;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37496344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档