如何解决Microsoft JScript运行时错误:'google.visualization.Dashboard'为null或不是对象 [英] How To Solve Microsoft JScript runtime error: 'google.visualization.Dashboard' is null or not an object

查看:67
本文介绍了如何解决Microsoft JScript运行时错误:'google.visualization.Dashboard'为null或不是对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<head  runat="server">

<title></title>>  
 <script type="text/javascript" src="https://www.google.com/jsapi"></script>

    
  
</head>;
<body>
   <form id="form1"  runat="server">
    <div>
    
   

        <asp:Literal ID="lt" runat="server">  
<div id="dashboard_div">
      <!--Divs that will hold each control and chart-->
    <div id="filter_div"></div>
      <div id="chart_div"></div>            

    
    </div>;
     </div>
    </form>
</body>







我的C#代码: -






my C# Code:-

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;

public partial class dashboard : System.Web.UI.Page
{
    StringBuilder str = new StringBuilder();

    //Get connection string from web.config

    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

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

            BindChart();

        }


    }
    private DataTable GetData()
    {

        DataTable dt = new DataTable();

        string cmd = "select YEAR,sales from area_chart";

        SqlDataAdapter adp = new SqlDataAdapter(cmd, constr);

        adp.Fill(dt);

        return dt;

    }
    private void BindChart()
    {

        DataTable dt = new DataTable();

        try
        {

            dt = GetData();

            str.Append(@" <script type='text/javascript'>

                         google.load('visualization', '1.0', {'packages':['controls']});



                         google.setOnLoadCallback(drawRegionsMap);

                          function drawRegionsMap() {

                            var data = google.visualization.arrayToDataTable([

                              ['YEAR','sales'],");



            int count = dt.Rows.Count - 1;

            for (int i = 0; i <= count; i++)
            {

                str.Append("['" + dt.Rows[i]["YEAR"].ToString() + "',  " + dt.Rows[i]["sales"].ToString() + "],");

                if (i == count)
                {

                    str.Append("['" + dt.Rows[i]["YEAR"].ToString() + "',  " + dt.Rows[i]["sales"].ToString() + "]]);}");

                }
              

            }
            // Create a dashboard.

            str.Append("var dashboard1 = new google.visualization.Dashboard(document.getElementById('dashboard_div'));");

            // Create a range slider, passing some options

            str.Append("var yearslider = new google.visualization.ControlWrapper({ 'controlType': 'NumberRangeFilter',    'containerId': 'filter_div', 'options': { 'filterColumnLabel': 'YEAR' }});");

            // Create a pie chart, passing some options
            str.Append("var pieChart = new google.visualization.ChartWrapper({'chartType': 'PieChart','containerId': 'chart_div', 'options': { 'width': 300,'height': 300,'pieSliceText': 'value', 'legend': 'right' } });");


            // Establish dependencies, declaring that 'filter' drives 'pieChart',
            // so that the pie chart will only display entries that are let through
            // given the chosen slider range.
            str.Append("dashboard1.bind(yearslider , pieChart);");

            // Draw the dashboard.
            str.Append("dashboard1.draw(data);");



            //str.Append("var options = { title:'year And Expance',hAxis: {title: 'Year',  titleTextStyle: {color: '#333'}},};var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));");

            //str.Append("chart.draw(data, options);};");


            str.Append("</script>");

            lt.Text = str.ToString();

        }

        catch
        {

        }

    }

}






当执行此错误时
像这样来我怎么解决

1)Microsoft JScript运行时错误:'google.visualization.Dashboard'为null或不是对象

2)Microsoft JScript运行时错误: 'google.visualization.ControlWrapper'为null或不是对象

3)Microsoft JScript运行时错误:'dashboard1'为null或不是对象

我怎么能把这些错误帮助我




when e execute this error coming like this how can i solve
1)Microsoft JScript runtime error: 'google.visualization.Dashboard' is null or not an object
2)Microsoft JScript runtime error: 'google.visualization.ControlWrapper' is null or not an object
3)Microsoft JScript runtime error: 'dashboard1' is null or not an object
how can i sove these errors help me

推荐答案





这是一个明确定义的Google数据可视化示例,< br $> b $ b

https://开发人员.google.com / chart / interactive / docs / gallery / controls?hl = en [ ^ ]



现在你的情况:



我搞砸了它: https://jsfiddle.net/mghu803f/ [< a href =https://jsfiddle.net/mghu803f/target =_ blanktitle =New Window> ^ ]



查看它并回复你想要的东西。
Hi,

This is a well defined example of Google data visualization,

https://developers.google.com/chart/interactive/docs/gallery/controls?hl=en[^]

Now in your case :

I have fiddled it : https://jsfiddle.net/mghu803f/[^]

Just view it and reply what you want is this it.


这篇关于如何解决Microsoft JScript运行时错误:'google.visualization.Dashboard'为null或不是对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆