Google图表分为两部分

时间:2019-06-08 13:31:26

标签: charts google-visualization linechart

我以正确的顺序给出了数据。渲染以某种方式在 2019年和2018年,也都是2019年,然后是2018年。对此是否有解决方法?还是某些导致这种情况发生的财产?enter image description here

代码如下:

import {GoogleCharts} from 'google-charts';
    let graphRows = []
    graphs[index].forEach(element => {
        let dataArray = [];
        dataArray.push(new Date(element["Date"].toString()));
        dataArray.push(element['Net Asset Value']);
        graphRows.push(dataArray);
    });

    //Load the charts library with a callback
    GoogleCharts.load(drawChart);

    function drawChart() {

        // Standard google charts functionality is available as GoogleCharts.api after load
        const data = new GoogleCharts.api.visualization.DataTable();
        data.addColumn('date', 'Time');
        data.addColumn('number', 'Net Asset Value');


        data.addRows(graphRows);
        // data.addRows(graphRowsReversed);

        var options = {
            hAxis: {
                title: 'Date'
            },
            vAxis: {
                title: 'Value'
            },
            explorer: { axis: 'horizontal' }
        };
        const line_chart = new GoogleCharts.api.visualization.LineChart(document.getElementById('chart-div'));
        line_chart.draw(data, options);
    }

graphs[index]是一个对象数组,每个对象看起来像这样:

{
    "Scheme Code": 145633,
    "Scheme Name": "Mirae Asset Nifty 50 ETF (MAN50ETF)",
    "ISIN Div Payout": {
     "ISIN Growth": "INF769K01EG9"
    },
    "ISIN Div Reinvestment": "",
    "Net Asset Value": 116.917,
    "Repurchase Price": null,
    "Sale Price": null,
    "Date": "09-Apr-2019"
}

0 个答案:

没有答案