谷歌仪表板图不是在ASP如何产生

谷歌仪表板图不是在ASP如何产生

本文介绍了谷歌仪表板图不是在ASP如何产生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图生成根据不断变化的MTBF值的仪表板图,但是当我运行web应用,我没有看到任何图表,只需按按钮。是我的方向是正确的做法。感谢您的帮助,

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;命名空间WebApplication1
{
    公共部分类WebForm3:System.Web.UI.Page
    {        保护无效的Page_Load(对象发件人,EventArgs的发送)
        {        }        保护无效的button1_Click(对象发件人,EventArgs的发送)
        {
            使用(Test_Manager_DatabaseEntities实体=新Test_Manager_DatabaseEntities())
            {
                INT TestExecID = Convert.ToInt32(的Request.QueryString [流程id]);
                变种执行= entities.TestExecutionDetails.Where(p值=> p.TestExecutionID == TestExecID)。选择(p值=指p).OrderBy(p值=> p.StartTime).ToArray();
                VAR失败= entities.TestExecutionDetails.Select(P => p.Result =通行证!).Count之间的();
                变种数= entities.TestExecutionDetails.Count();
                变种的正常运行时间= entities.TestExecutionDetails.Where(p值=> p.Result ==通过)。选择(p值=指p);
                时间跨度elapsedDuration =新的时间跨度(0);
                的foreach(在正常运行时间VAR P)
                {                    elapsedDuration + =(p.EndTime.Value - p.StartTime.Value);                }
                VAR mtbfdisplay = elapsedDuration.TotalSeconds /故障;
                串STR1 = @        数据= google.visualization.arrayToDataTable([;                字符串STR2 = @[标签,值],[MTBF,+ mtbfdisplay + @]]);;                字符串STR3 = @变种选项= {
                宽度:400,高度:120,redFrom:90,redTo:100,yellowFrom:75,yellowTo:90,器minorTicks:5
            };
                VAR图=新google.visualization.gauge(的document.getElementById('排行榜成功'));
                drawchart(数据,选项);;                字符串POSTDATA = STR1 + STR2 + STR3;                Console.WriteLine(POSTDATA);
                ScriptManager.RegisterClientScriptBlock(这一点,this.GetType(),测试,POSTDATA,真正的);            }
        }
    }
}

的.aspx

 <%@页面语言=C#AutoEventWireup =真codeBehind =WebForm3.aspx.cs继承=WebApplication1.WebForm3%GT;<!DOCTYPE HTML>< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <标题>< /标题>
< /头>
<身体GT;
    <表ID =form1的=服务器>
        <脚本类型=文/ JavaScript的SRC =htt​​ps://www.google.com/jsapi>< / SCRIPT>
    <脚本类型=文/ JavaScript的SRC =htt​​p://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js>< / SCRIPT>        < ASP:的ScriptManager ID =ScriptManager1=服务器>
        < / ASP:ScriptManager的>
        < ASP:标签ID =Label2的=服务器文本=1>< / ASP:标签>
                < BR />
    < D​​IV>
        < ASP:的UpdatePanel ID =UpdatePanel1=服务器>
            <&的ContentTemplate GT;                < ASP:HiddenField ID =HiddenField1=服务器VALUE =1/>
                < BR />                < ASP:标签ID =Label1的=服务器文本=1>< / ASP:标签>
                < BR />                < ASP:按钮的ID =Button1的=服务器文本=按钮的OnClick =的button1_Click/>                < D​​IV ID =排行榜成功>< / DIV>            < /&的ContentTemplate GT;
        < / ASP:的UpdatePanel>
    < / DIV>
    < /表及GT;
< /身体GT;
< / HTML>


解决方案

有几个问题,你的脚本比较的:


  1. 必需的包加载跳过

  2. 拼写错误 google.visualization.Gauge 构造

  3. 无功能 drawchart - presumably应该有 chart.draw

我试图纠正你的脚本,这里是结果(不知道这是否是你,尽管正在实施的):

 字符串POSTDATA = @
    的google.load('可视化','1',{软件包:['规']});
    google.setOnLoadCallback(drawGaugeChart);    功能drawGaugeChart(){
        数据= google.visualization.arrayToDataTable(['标签','值'],[MTBF,+ mtbfdisplay + @]]);
        VAR的选择= {
            宽度:400,高度:120,redFrom:90,redTo:100,yellowFrom:75,yellowTo:90,器minorTicks:5
        };
        VAR图=新google.visualization.Gauge(的document.getElementById('排行榜成功'));
        chart.draw(数据,选项);
    };

I'm trying to generate a gauge chart based on changing MTBF values, However when I run the webapplication, I don't see any chart, just the button. Is my approach in the right direction. Thanks for all your help,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm3 : System.Web.UI.Page
    {



        protected void Page_Load(object sender, EventArgs e)
        {



        }

        protected void Button1_Click(object sender, EventArgs e)
        {


            using (Test_Manager_DatabaseEntities entities = new Test_Manager_DatabaseEntities())
            {


                int TestExecID = Convert.ToInt32(Request.QueryString["ExecutionID"]);
                var execution = entities.TestExecutionDetails.Where(p => p.TestExecutionID == TestExecID).Select(p => p).OrderBy(p => p.StartTime).ToArray();
                var failures = entities.TestExecutionDetails.Select(p => p.Result != "Pass      ").Count();
                var count = entities.TestExecutionDetails.Count();
                var uptime = entities.TestExecutionDetails.Where(p => p.Result == "Pass          ").Select(p => p);
                TimeSpan elapsedDuration = new TimeSpan(0);
                foreach (var p in uptime)
                {

                    elapsedDuration += (p.EndTime.Value - p.StartTime.Value);

                }
                var mtbfdisplay = elapsedDuration.TotalSeconds / failures;


                string str1 = @"

        data = google.visualization.arrayToDataTable([";

                string str2 = @"['Label', 'Value'],['MTBF'," + mtbfdisplay + @"],]);";

                string str3 = @"var options = {
                width: 400, height: 120, redFrom: 90, redTo: 100, yellowFrom: 75, yellowTo: 90, minorTicks: 5
            };


                var chart = new google.visualization.gauge(document.getelementbyid('chart-success'));
                drawchart(data, options);";

                string postData = str1 + str2 + str3;

                Console.WriteLine(postData);


                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", postData, true);

            }


        }
    }
}

.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Label ID="Label2" runat="server" Text="1"></asp:Label>
                <br />
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                <asp:HiddenField ID="HiddenField1" runat="server" Value="1" />
                <br />

                <asp:Label ID="Label1" runat="server" Text="1"></asp:Label>
                <br />

                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

                <div id="chart-success"></div>

            </ContentTemplate>


        </asp:UpdatePanel>
    </div>


    </form>
</body>
</html>
解决方案

There were several problems with your script comparing to this example from documentation:

  1. Loading of necessary packages was skipped
  2. Misspelled google.visualization.Gauge constructor
  3. No function drawchart - presumably there should be chart.draw

I have tried to correct your script, and here is the result (not sure if this is what you were implementing though):

string postData = @"
    google.load('visualization', '1', {packages:['gauge']});
    google.setOnLoadCallback(drawGaugeChart );

    function drawGaugeChart() {
        data = google.visualization.arrayToDataTable([['Label', 'Value'],['MTBF'," + mtbfdisplay + @"]]);
        var options = {
            width: 400, height: 120, redFrom: 90, redTo: 100, yellowFrom: 75, yellowTo: 90, minorTicks: 5
        };
        var chart = new google.visualization.Gauge(document.getElementById('chart-success'));
        chart.draw(data, options);
    }";

这篇关于谷歌仪表板图不是在ASP如何产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:14