给定轴上的所有系列必须与Google图表具有相同的数据类型

时间:2015-09-11 15:30:46

标签: javascript c# types google-visualization

我知道之前有人问过,但我真的无法理解这一点。我已经尝试了一切来摆脱这个错误,但它不会消失。这是我的代码,生成我的图表时会收到以下错误消息:给定轴上的所有系列必须具有相同的数据类型。

C#

public static object[][] GetBarData()
{
    string strSQL = @"SELECT [Expected Month] , ISNULL([0],0) AS [0],
                        ISNULL([0.10],0) AS [10],
                        ISNULL([0.25],0) AS [25],
                        ISNULL([0.50],0) AS [50],
                        ISNULL([0.75],0) AS [75],
                        ISNULL([0.90],0) AS [90],
                        ISNULL([1.00],0) AS [100]
     FROM (
        SELECT MONTH(D.expected_date) AS [Expected Month], P.probability AS [Category], COUNT(O.id) AS [Customers]
    FROM opportunity_probability P
        INNER JOIN opportunity_detail D ON D.probability_id = P.id
        INNER JOIN opportunities O ON D.opportunity_id = O.id
        INNER JOIN (SELECT opportunity_id FROM opportunity_detail GROUP BY opportunity_id) T ON T.opportunity_id = O.customer_id
        GROUP BY P.probability, MONTH(D.expected_date)
        ) ST
            PIVOT (
                SUM([Customers])
                FOR [Category] IN ([0],[0.10],[0.25],[0.50],[0.75],[0.90],[1.00])
            ) PIV";

    DataTable dt = MIDB.DataAccess.LoadDTFromSQL(System.Configuration.ConfigurationManager.ConnectionStrings["MIDB"].ConnectionString, strSQL);

    return dtToArray(dt, new Object[9] { "Period", "0%", "10%", "25%", "50%", "75%", "90%", "100%", "Customers" });
}


public static object[][] dtToArray(DataTable dt, Object[] header)
{
    Object[][] obj = new Object[dt.Rows.Count + 1][];
    obj[0] = header;
    int k = header.Length;
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        DataRow row = dt.Rows[i];
        obj[i + 1] = new object[k];
        for (int j = 0; j < dt.Columns.Count; j++)
        {
            if (dt.Columns[j].DataType == Type.GetType("System.Decimal"))
            {

                obj[i + 1][j] = Convert.ToDouble(row[j]);
            }
            else if (dt.Columns[j].DataType == Type.GetType("System.Int32"))
            {

                obj[i + 1][j] = Convert.ToInt32(row[j]);
            }
            else if (dt.Columns[j].DataType == Type.GetType("System.DateTime"))
            {
                obj[i + 1][j] = GenericMethods.jsMilliseconds(Convert.ToDateTime(row[j]));
            }
            else
            {
                obj[i + 1][j] = row[j].ToString();
            }
        }
    }
    return obj;
}

google.load("visualization", "1.1", {
        packages: ["bar", "corechart"]
    });

ASPX页面

    $(document).ready(function () {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            url: 'PipelineChart.aspx/GetChartData',
            success:
                function (response) {
                    genCharts(response.d);
                }
        });
    })

    $(window).resize(function () {
        getDataPost();
    });

    function getDataPost() {
        $(document).ready(function () {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                url: 'PipelineChart.aspx/GetChartData',
                success:
                    function (response) {
                        genCharts(response.d);
                    }
            });
        })
    }

    function genCharts(obj) {
        drawBar(obj[0]);
    }

    function drawBar(obj) {
        var data = google.visualization.arrayToDataTable(obj);

        var options = {
            width: '100%',
            height: '600',
            isStacked: true
        }

        var chart = new google.visualization.BarChart(document.getElementById('Bar'));
        chart.draw(data, options)
    }

    google.setOnLoadCallback(drawBar);

0 个答案:

没有答案