-1

我是剑道的新手,只是在试用它。我正在查看演示中提供的折线图示例上的组绑定。我在演示中链接了远程 json,但无法使图表正常工作。如果我导航到 json 链接,则 json 显示正常。任何帮助将不胜感激。

演示链接:http ://demos.kendoui.c​​om/dataviz/line-charts/remote-data.html

链接到我的代码:http: //jsfiddle.net/Grjsn/3/

代码文本:

<div id="example" class="k-content absConf">
     <div class="chart-wrapper" style="margin: auto;">
      <div id="chart"></div>
</div>

<script>
function createChart() {
                    $("#chart").kendoChart({
                        dataSource: {
                            transport: {
                                read: {
                                    url: "http://demos.kendoui.com/content/dataviz/js/spain-electricity.json",
                                    dataType: "json"
                                }
                            },
                            sort: {
                                field: "year",
                                dir: "asc"
                            }
                        },
                        title: {
                            text: "Spain electricity production (GWh)"
                        },
                        legend: {
                            position: "top"
                        },
                        seriesDefaults: {
                            type: "line"
                        },
                        series:
                        [{
                            field: "nuclear",
                            name: "Nuclear"
                        }, {
                            field: "hydro",
                            name: "Hydro"
                        }, {
                            field: "wind",
                            name: "Wind"
                        }],
                        categoryAxis: {
                            field: "year",
                            labels: {
                                rotation: -90
                            }
                        },
                        valueAxis: {
                            labels: {
                                format: "N0"
                            },
                            majorUnit: 10000
                        },
                        tooltip: {
                            visible: true,
                            format: "N0"
                        }
                    });
                }

                $(document).ready(function() {
                    setTimeout(function() {
                        // Initialize the chart with a delay to make sure
                        // the initial animation is visible
                        createChart();

                        $("#example").bind("kendo:skinChange", function(e) {
                            createChart();
                        });
                    }, 400);
                });
</script>
4

1 回答 1

1

加载 JSON 会引发错误:

XMLHttpRequest 无法加载http: //demos.kendoui.c​​om/content/dataviz/js/spain-electricity.json 。Access-Control-Allow-Origin 不允许来源http://fiddle.jshell.net 。

这是由于浏览器中 AJAX 请求的同源安全性。

http://en.wikipedia.org/wiki/Same_origin_policy

于 2013-05-09T01:45:30.857 回答