我的应用程序运行没有任何错误,但我没有得到仪表图像

时间:2015-02-14 10:44:26

标签: c# asp.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Configuration;
using System.Data;
using MySql.Data.MySqlClient;

public partial class PerformanceChart : System.Web.UI.Page
{
    StringBuilder str = new StringBuilder();
    MySqlConnection conn = new MySqlConnection("server=****;user id=***;Password=****;database=****");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            BindChart();
        }
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        string cmd = "SELECT COUNT(IF(Status='A',1,NULL))'OPEN',COUNT(IF(Status='D',1,NULL))'CLOSE', YEAR(Start_Date_Time) FROM sh_report WHERE YEAR(Start_Date_Time)>=DATE_SUB(CURDATE(),INTERVAL 1 YEAR) GROUP BY YEAR(Start_Date_Time)";
        MySqlDataAdapter da = new MySqlDataAdapter(cmd, conn);
        da.Fill(dt);
        return dt;
    }

    private void BindChart()
    {
        DataTable dt = new DataTable();
        try
        {
            dt = GetData();

            str.Append(@"<script type=text/javascript> google.load( *visualization*, *1*, {packages:[*gauge*]});
                        google.setOnLoadCallback(drawChart);
                        function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string','YEAR(Start_Date_Time)');
            data.addColumn('number','COUNT');

            data.addRows(" + dt.Rows.Count + ");");

            for (int i = 0; i <= dt.Rows.Count - 1; i++)
            {
                str.Append("data.setValue(" + i + "," + 0 + "," + "'" + dt.Rows[i]["YEAR(Start_Date_Time)"].ToString() + "');");
                str.Append("data.setValue(" + i + "," + 1 + "," + dt.Rows[i]["COUNT)"].ToString() + ");");
            }
            str.Append("var options = {width:600,height:300,redFrom:90,redTo:100,yellowFrom:75,yellowTo:90,minorTicks:5};");
            str.Append("var chart = new google.visualization.Gauge(document.getElementById('chart_div'));");
            str.Append("chart.draw(data,options);}");
            str.Append("</script>");
            lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
        }
        catch
        { }
    }
}


My ASPX page code :


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PerformanceChart.aspx.cs" Inherits="PerformanceChart" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="chart_div">
    </div>
        <asp:Literal ID="lt" runat="server"></asp:Literal>
    </form>
</body>
</html>

每件事情都很好但不显示o / p任何人都可以帮助我。 这段代码有什么不妥。我尝试了很多方法,但它没有显示计量表。我是asp.net的新手,我需要你提前帮助你

0 个答案:

没有答案