使用 jquery 和 Abp.net C# 服务从数据库获取数据并将其显示在折线图中

Getting data from db and display it in line chart using jquery and Abp.net C# service

当我 运行 大摇大摆时,我可以看到我的服务 return 数据,但是如果我 运行 MVC 给我错误无法显示图表。需要帮助和图表是通过数据库中的条目计数显示月度报告,以通过图表显示成功、待处理和失败。

我的jquery

 google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
    $.ajax({
    type: "GET",
    url: "/idMSDashboard/GetMonthlyVerStatCountAsync",
    contentType: "application/json",
    success: function (data) {
        var data = GetMonthlyVerStatCountAsysnc();

    var options = {
        title: '',
        width: '100%',
        colors: ['green', 'orange', 'red'],
        curveType: 'function',
        legend: { position: 'bottom' }
    };

    var chart = new google.visualization.LineChart(document.getElementById('top_x_div'));

    chart.draw(data, options)
    $(window).resize(function () {
        drawChart();
    });
    },
    error: function () {
        $('.loader-wrapper').addClass('hidden');
        abp.notify.error("An error occurred while retrieving Monthly Verification  stats. Contact support", "Error");
        abp.ui.clearBusy();
    }
});
    
}

我的 C# 服务正在运行,因为我确实检查了我的 swagger,它 return 是数据,但 jquery 是我的问题需要帮助

 public async Task<idMSDashboard_Dto> GetMonthlyVerStatCountAsync()
    {
        try
        {
            using (var conn = new OracleConnection(_configuration.GetConnectionString("Payment")))
            {
                using (var cmd = conn.CreateCommand())
                {
                    conn.Open();
                    using (var unitOfWork = _unitOfWorkManager.Begin())
                    {
                        string monthVerificationStat_sql = @"SELECT CASE WHEN MONTH_NUM = 1 THEN 'JAN' WHEN MONTH_NUM = 2 THEN 'FEB' WHEN MONTH_NUM = 3 THEN 'MAR' WHEN MONTH_NUM = 4 THEN 'APR' WHEN MONTH_NUM = 5 THEN 'MAY'
                                                              WHEN MONTH_NUM = 6 THEN 'JUN' WHEN MONTH_NUM = 7 THEN 'JUL' WHEN MONTH_NUM = 8 THEN 'AUG' WHEN MONTH_NUM = 9 THEN 'SEP' WHEN MONTH_NUM = 10 THEN 'OCT'
                                                              WHEN MONTH_NUM = 11 THEN 'NOV' WHEN MONTH_NUM = 12 THEN 'DEC' END AS MONTH, 
                                                              COUNT(SUCCESSFULVERIFICATION) AS SUCCESSFULVERIFICATION, COUNT(PENDINGVERIFICATION) AS PENDINGVERIFICATION, COUNT(FAILEDVERIFICATION) AS FAILEDVERIFICATION
                                                              FROM(SELECT EXTRACT(MONTH FROM PAYMENTDATE) MONTH_NUM, CASE WHEN NIMC_STATUS = 1 THEN 1 END AS SUCCESSFULVERIFICATION,
                                                              CASE WHEN NIMC_STATUS = 2 THEN 1 END AS PENDINGVERIFICATION, CASE WHEN NIMC_STATUS = 0 THEN 1 END AS FAILEDVERIFICATION FROM PAYMENT_REF_TABLE
                                                              WHERE EXTRACT(Year FROM PAYMENTDATE)  = :YEAR) A GROUP BY MONTH_NUM ORDER BY MONTH_NUM";
                        var @monthVerificationStat = conn.Query<monthVerificationStat>(monthVerificationStat_sql, new
                        {
                            YEAR = DateTime.Now.Year.ToString()
                        });
                        await unitOfWork.CompleteAsync();
                        return new idMSDashboard_Dto
                        {
                            monthVerificationStat = monthVerificationStat
                        };


                    }
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Error("An error occured in GetMonthlyVerStatCountAsync Type of error : " + ex.GetType() + ". Error message: " + ex.Message + "Exception data : " + ex.Data + "Exception numerical code : " + ex.HResult + "TargetSite : " + ex.TargetSite + "Exception source " + ex.Source);
            return null;
        }
    }

在此代码行中:

var data = GetMonthlyVerStatCountAsysnc();

您正在覆盖从服务器返回的现有数据:

success: function (data) {

所以你使用的数据不是从服务器返回的数据,那一定是你面临的问题。