Error loading google api Chart in ASP.net

Asked

Viewed 58 times

0

When I took the example of the site worked, but when I include a new Webform and in a new project and paste the codes of the codebehind example in VB.net and the aspx code does not work, gives the warning message, I made some adaptations in the collection of 3 points to make it easier to run the example. Some days I try. Can you help? Uso visualstudio Express 2017

aspx code:

<%@ Page Title="" Language="vb" AutoEventWireup="false" 
MasterPageFile="~/Site.Master" CodeBehind="teste1.aspx.vb" 
Inherits="SIIv3.teste1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    google.load('visualization', '1', { packages: ['corechart'] });
</script>
<script type="text/javascript">
    $(function () {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            url: 'teste1.aspx/GetDadosGrafico',
            data: '{}',
            success:
            function (response) {
                drawchart(response.d);
            },
            error: function () {
                alert("Issue to load Data.");
            }
        });
    })
    function drawchart(dataValues) {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Column Name');
        data.addColumn('number', 'Column Value');
        for (var i = 0; i < dataValues.length; i++) {
            data.addRow([dataValues[i].Silos, dataValues[i].Total]);
        }
        new google.visualization.PieChart(document.getElementById('chartdiv')).
            draw(data, { title: "JcmSoft - Participação Mercado por País" });
    }
</script>



<div id="chartdiv" style="width: 590px; height: 201px;">
</div>


</asp:Content>

VB.net codebehind

Imports System.Web.Services

Partial Class teste1
Inherits Page


<WebMethod>
Public Shared Function GetDadosGrafico() As List(Of DadosDetalhes)
    Dim listaDados As New List(Of DadosDetalhes)()

    Dim details As New DadosDetalhes With {
        .Silos = "silo",
        .Total = 13
    }
    listaDados.Add(details)

    details = New DadosDetalhes With {
        .Silos = "silo1",
        .Total = 20
    }
    listaDados.Add(details)

    details = New DadosDetalhes With {
        .Silos = "silo2",
        .Total = 5
    }
    listaDados.Add(details)

    Return listaDados
End Function

End Class

Public Class DadosDetalhes
    Public Property Silos() As String
    Public Property Total() As Integer
End Class
  • If you’re starting the project, and it’s not big. I recommend you move on to using ASP.NET Core Razor Pages or ASP.NET MVC, because ASP.NET Webforms is already " deprecated" and will no longer receive updates with news.

  • thank you, I’ll try.

  • If you only use visual basic, then study about the MVC, for Razor Pages supports only C#.

  • I researched about your suggestion, but I found very complex the use of MVC, we must have a very high knowledge for creating controllers, views, tasks and etc... My project is very simple. I will basically use gridview and some charts collecting oracle BD data, which is why I opted for Asp.net. Do you have any suggestions on how to create webforms for IIS simply by dragging the components? I appreciate your help.

  • If you are using Visual Studio, when you open a file .aspx, right after the code, below. It has 3 buttons, you can click on "Design" and do the same way you do with Windows Forms: See here an example image.

  • good evening, I decided to program in Asp.net mvc as per your tip. At first it was difficult, but I’m getting the morning. thanks for the tip.

  • Good, congratulations! It’s hard even at the beginning, I had enough difficulty, but it’s worth it :)

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.