Google Visualization API 在本地工作,但不在外部服务器上工作?

发布于 2024-11-07 08:29:32 字数 400 浏览 3 评论 0原文

我正在使用 Google Visualization API 和 jQuery 构建一个动态饼图来显示选举结果,并且我让它(在某种程度上)在我的本地计算机上运行,​​并且想要获得一些反馈,因此现在将其上传到外部服务器我尝试加载的所有内容都会出现“无数据”错误。

我有两个文件,一个从数据库获取数据并将其转换为 JSON,另一个显示可视化效果,具体取决于检查的区域。您可以在这里查看:

http://www2.lichfielddc.gov.uk /sandbox/pie.php?electionid=14

有什么想法我哪里出错了吗?

干杯

I'm building a dynamic pie chart to show election results using the Google Visualization API and jQuery, and I had it (sort of) working on my local machine, and wanted to get some feedback, so uploaded it to an external server, now everything I try to load gives me a "No Data" error.

I've got two files, one which gets data from a database and converts it to JSON, and one which displays the visualization, depending on what areas are checked. You can see it here:

http://www2.lichfielddc.gov.uk/sandbox/pie.php?electionid=14

Any ideas where I'm going wrong?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风为裳 2024-11-14 08:29:32

我想我可能正在做某事。

我下载了它并在本地进行了测试,正如您所说,它工作正常。但是,在我使用的数据源(data.php)中,如果我设置延迟(睡眠(1)),它就会停止工作。我认为这是因为您正在从 ajax 成功回调中绘制图表。

试试这个:

    function drawVisualization() {          
    $('.poll').click(function() {

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Party');
    data.addColumn('number', 'Votes');

        var polls = [];

        $('.poll:checked').each(function(){
            polls.push(this.value);
        });

        polls.join(",");

        url = "http://www2.lichfielddc.gov.uk/sandbox/piedata.php?pollid=" + polls;

        $.getJSON(url, function(d) {

            data.addRows(d.length);

            var items = [];
            var num = 0;

            $.each(d, function(i, o) {

                console.log(o);

                data.setValue(num, 0, o['party']);
                data.setValue(num, 1, o['votes']);

                num++;

            });

            new google.visualization.PieChart(document.getElementById('visualization')).
            draw(data);
        });
    });

Think I may be on to something.

I downloaded it and tested it locally and as you said it works fine. However, in the datasource i was using (data.php) if I put a delay (sleep(1)) it stopped working. I think it was because you were drawing the chart out of the ajax success callback.

Try this:

    function drawVisualization() {          
    $('.poll').click(function() {

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Party');
    data.addColumn('number', 'Votes');

        var polls = [];

        $('.poll:checked').each(function(){
            polls.push(this.value);
        });

        polls.join(",");

        url = "http://www2.lichfielddc.gov.uk/sandbox/piedata.php?pollid=" + polls;

        $.getJSON(url, function(d) {

            data.addRows(d.length);

            var items = [];
            var num = 0;

            $.each(d, function(i, o) {

                console.log(o);

                data.setValue(num, 0, o['party']);
                data.setValue(num, 1, o['votes']);

                num++;

            });

            new google.visualization.PieChart(document.getElementById('visualization')).
            draw(data);
        });
    });
诠释孤独 2024-11-14 08:29:32

单步执行代码:当您调用draw()方法时,对象“data”中没有数据。这可能是因为对数据对象的修改不在同一范围内。

Stepping through the code: By the time you call the draw() method, the object 'data' has no data in it. This is likely because the modifications to the data object are not in the same scope.

Smile简单爱 2024-11-14 08:29:32

我同意 Tribal 的观点,这是一个时间问题,因为现场版本有时确实有效。还有一些其他潜伏的错误,它们并不是当前问题的背后,但是...

polls.join(",");
url = "http://www2.lichfielddc.gov.uk/sandbox/piedata.php?pollid=" + polls;

polls.join() 返回一个字符串,它不会就地进行连接。并且 url 没有被声明为局部变量

I agree with Tribal that it's a timing issue, because the live version does work sometimes. There's a couple of other lurking bugs, that aren't behind the presenting issue, but ...

polls.join(",");
url = "http://www2.lichfielddc.gov.uk/sandbox/piedata.php?pollid=" + polls;

polls.join() returns a string, it doesn't do the join in-situ. And url isn't being declared as a local variable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文