Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将XML解析为JSON-Javascript时遇到问题_Javascript_Jquery_Xml_Highcharts - Fatal编程技术网

将XML解析为JSON-Javascript时遇到问题

将XML解析为JSON-Javascript时遇到问题,javascript,jquery,xml,highcharts,Javascript,Jquery,Xml,Highcharts,我正在尝试使用Javascript/Jquery将一些XML数据解析为JSON,以便在Highcharts项目中使用。不幸的是,我无法找出我的代码有什么问题,因为它甚至无法读取XML。到目前为止,我已经: xml: 数据 数据 .... HTML: 文件 你好 Javascript: $(document).ready(function(){ var globalData = new Array(); // $("h1").click(function(){ // Load

我正在尝试使用Javascript/Jquery将一些XML数据解析为JSON,以便在Highcharts项目中使用。不幸的是,我无法找出我的代码有什么问题,因为它甚至无法读取XML。到目前为止,我已经:

xml:


数据
数据
....
HTML:


文件
你好
Javascript:

$(document).ready(function(){

var globalData = new Array();

// $("h1").click(function(){
    // Load the data from the XML file 
    $.get('C:\\Users\\xxxxxx\\Desktop\\xmloutput.xml', function(xml) {
        alert("it works");

        // Split the lines
        var $xml = $(xml);

        // push series
        $xml.find('Row').each(function(i, row) {
            var seriesOptions = {
                Category: $(series).find('Category').text(),
                Actual: $(series).find('Actual').text(),
            };

            // add it to the options
            globalData.push(seriesOptions);
        });


    });
// });


$(function() {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'pie'
        },

        plotOptions: {
            pie: {
                borderColor: '#000000',
                innerSize: '60%'
            }
        },
        series: [{
            data: globalData
        }]
    },
    // using 

    function(chart) { // on complete

        var xpos = '50%';
        var ypos = '53%';
        var circleradius = 102;

    // Render the circle
    chart.renderer.circle(xpos, ypos, circleradius).attr({
        fill: '#ddd',
    }).add();

    // Render the text 
    chart.renderer.text('THIS TEXT <span style="color: red">should be in the center of the donut</span>', 155, 215).css({
            width: circleradius*2,
            color: '#4572A7',
            fontSize: '16px',
            textAlign: 'center'
      }).attr({
            // why doesn't zIndex get the text in front of the chart?
            zIndex: 999
        }).add();
    });
});


});
$(文档).ready(函数(){
var globalData=新数组();
//$(“h1”)。单击(函数(){
//从XML文件加载数据
$.get('C:\\Users\\xxxxxx\\Desktop\\xmloutput.xml',函数(xml){
警惕(“它起作用”);
//分道扬镳
var$xml=$(xml);
//推送系列
$xml.find('Row')。每个(函数(i,Row){
var系列选项={
类别:$(系列).find('Category').text(),
实际值:$(系列).find('Actual').text(),
};
//将其添加到选项中
全局数据推送(系列选项);
});
});
// });
$(函数(){
var图表=新的Highcharts.图表({
图表:{
renderTo:'容器',
键入:“馅饼”
},
打印选项:{
馅饼:{
边框颜色:'#000000',
内部尺寸:“60%”
}
},
系列:[{
数据:globalData
}]
},
//使用
函数(图表){//已完成
var xpos='50%';
var ypos='53%';
循环变异系数=102;
//画圆
chart.renderer.circle(xpos、ypos、circleradius).attr({
填写:“#ddd”,
}).add();
//渲染文本
chart.renderer.text('此文本应位于甜甜圈的中心',155215)。css({
宽度:圆形*2,
颜色:“#4572A7”,
fontSize:'16px',
textAlign:“中心”
})艾特先生({
//为什么zIndex不把文本放在图表前面?
zIndex:999
}).add();
});
});
});
我相信我的实际问题可能是我的xml解析语法不正确,但在Firefox的开发控制台上运行它不会显示任何错误。希望这里的专家能够发现问题


谢谢您的时间。

我看到的一个即时问题是使用本地路径

$.get('C:\\Users\\xxxxxx\\Desktop\\xmloutput.xml',

$.get
第一个参数是url,它是网络上的位置,可能类似于
$.get('http://localhost/xmls/xmloutput.xml,…

无法解决问题,因为我看不到任何新的情况发生。这可能意味着我的代码有更多问题:(您可以从web应用程序中的路径读取xml,将要读取的xml放入该网站代码所在的文件夹,然后
http://localhost[您正在使用的端口]/xmloutput.xml
。网站无法查看
C:
文件夹中的内容。是否存在默认端口,我会在不知情的情况下使用?此网站目前只是一个原型,未托管。默认端口为80,但如果在访问网站时没有端口,请使用
http://localhost
通过$.get()函数使用webserver加载文件。
$(document).ready(function(){

var globalData = new Array();

// $("h1").click(function(){
    // Load the data from the XML file 
    $.get('C:\\Users\\xxxxxx\\Desktop\\xmloutput.xml', function(xml) {
        alert("it works");

        // Split the lines
        var $xml = $(xml);

        // push series
        $xml.find('Row').each(function(i, row) {
            var seriesOptions = {
                Category: $(series).find('Category').text(),
                Actual: $(series).find('Actual').text(),
            };

            // add it to the options
            globalData.push(seriesOptions);
        });


    });
// });


$(function() {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'pie'
        },

        plotOptions: {
            pie: {
                borderColor: '#000000',
                innerSize: '60%'
            }
        },
        series: [{
            data: globalData
        }]
    },
    // using 

    function(chart) { // on complete

        var xpos = '50%';
        var ypos = '53%';
        var circleradius = 102;

    // Render the circle
    chart.renderer.circle(xpos, ypos, circleradius).attr({
        fill: '#ddd',
    }).add();

    // Render the text 
    chart.renderer.text('THIS TEXT <span style="color: red">should be in the center of the donut</span>', 155, 215).css({
            width: circleradius*2,
            color: '#4572A7',
            fontSize: '16px',
            textAlign: 'center'
      }).attr({
            // why doesn't zIndex get the text in front of the chart?
            zIndex: 999
        }).add();
    });
});


});
$.get('C:\\Users\\xxxxxx\\Desktop\\xmloutput.xml',