Highchart js中的DIsplay Ajax数据

问题描述 投票:0回答:1

请让我的这个ajax代码正常运行,但是我的问题是如何在highchart上显示它。这是ajax代码

function ajaxGetRadiologyRecord() {
    let urlPath = 'http://' + window.location.hostname + ':8000/radiology/get-patient-radiology-record';
    let request = $.ajax({
        method: 'GET',
        url: urlPath,
    });
    request.done(function( response ) {
        console.log(response);
        let months = response.months;
        let monthlyRecord = response.monthly_record_count;
    });
}

当我记录响应时,数据中包含数组。即月份和记录。我将两个变量和月份分别保留为月和月。这是js高图表代码

Highcharts.chart('container', {
    chart: {
        type: 'column',
        events: {
            load: ajaxGetRadiologyRecord()
        }
    },
    title: {
        text: ''
    },
    xAxis: {
        categories: [
            'Jan',
            'Feb',
            'Masr',
            'Apr',
            'May',
            'Jun',
            'Jul',
            'Aug',
            'Sep',
            'Oct',
            'Nov',
            'Dec'
        ],
        crosshair: true
    },
    yAxis: {
        min: 0,
        title: {
            text: ''
        }
    },
    tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },
    exporting: {
        enabled: false
    },
    credits: {
        enabled: false
    },
    legend: {
        enabled: false
    },
    plotOptions: {
        column: {
            pointPadding: 0.2,
            borderWidth: 0,
            borderRadius: 2
        }
    },
    series: [{
        name: 'Patients',
        data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1],
        color: {
            linearGradient: {
                x1: 0,
                x2: 0,
                y1: 0,
                y2: 1
            },
            stops: [
                [0, 'rgba(153, 153, 153, 0.5)'],
                [1, '#f3f4f4']
            ]
        }

    }]
});

我现在的问题是如何用ajax中的months和data替换类别数组[]和ajax中的monthlyRecord。谢谢。

javascript ajax laravel highcharts
1个回答
0
投票

有不同的方法,但是您可以这样做,

var chart = Highcharts.chart('container', {
    chart: {
        type: 'column',
        events: {
            load: ajaxGetRadiologyRecord()
        }
    },
            . . .
    series: [
         {
            name: 'Patients',
            data: []
          }
        ]
});

在这里定义您的系列,可以定义多个系列

function ajaxGetRadiologyRecord() {
    let urlPath = 'http://' + window.location.hostname + ':8000/radiology/get-patient-radiology-record';
    $.ajax({
        method: 'GET',
        url: urlPath,
    });
    request.done(function( response ) {
        console.log(response);
        chart.addSeries({
          name: "Patients",
          data: response.monthly_record_count
        });
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.