2016-01-12 68 views
0

XML文件我有這樣一個xml:獲取值出來條形圖

<chart showValues="0" adjustDiv="0" showLabels="1" rotateLabels="1" slantLabels="1" xAxisName="" yAxisMinValue="-1" yAxisMaxValue="2" showYAxisValues="0" numDivLines="0" zeroPlaneAlpha="0" plotSpacePercent="10" plotFillRatio="100" caption="" labelStep="4" numVDivLines="15" vDivLineAlpha="10" animation="1" bgColor="FFFFFF" bgAlpha="0" showBorder="0" borderColor="415D6F" borderThickness="1" canvasBgColor="FFFFFF" canvasBgAlpha="100" canvasBorderColor="545454" canvasBorderAlpha="100" canvasBorderThickness="1" showCanvasBase="1" chartTopMargin="" chartLeftMargin="" chartRightMargin="" chartBottomMargin="-5" labelPadding="5" yAxisValuesPadding="7" hoverCapBgColor="ffffff" hoverCapBorderColor="708290" baseFont="Tahoma" baseFontSize="11" baseFontColor="535454" divLineColor="FFFFFF" divLineAlpha="65" divLineThickness="1" showAlternateHGridColor="0" alternateHGridColor="92CDD6" alternateHGridAlpha="10" legendBgColor="FFFFFF" legendBgAlpha="0" legendBorderColor="415D6F" legendBorderAlpha="50" legendBorderThickness="1" legendShadow="0" legendScrollBgColor="CCCCCC" legendScrollBarColor="CCCCCC" legendScrollBtnColor="999999" useRoundEdges="1"> 
    <categories> 
     <category label="00:00"/> 
     <category label="01:00"/> 
     <category label="02:00"/> 
    </categories> 
    <dataset> 
     <set value="2" color="8BBA00" alpha="100" toolText="Jan 12 24:00, Normal"/> 
     <set value="1" color="8BBA00" alpha="100" toolText="Jan 12 01:00, Warning"/> 
     <set value="1" color="8BBA00" alpha="100" toolText="Jan 12 02:00, Warning"/> 
    </dataset> 
</chart> 

我怎樣才能獲得「價值」出來的嗎?我需要一個條形圖的價值。 我認爲getElementsByTagName()在這種情況下不起作用?

回答

0

是的,你可以使用類似:

var sets = getElementsByTagName("set"); 
    for(i = 0;i < sets.length; i++) 
    { 
      var value = sets[i].getAttribute("value"); 
      // [...] 
    } 
0

使用jQuery

xmlDoc = $.parseXML(xmlString); 
var $xml = $(xmlDoc); 
$xml.find("set").each(function(index,node){ 
    console.log(node.getAttribute('value')); 
}); 

工作例Here

+0

與jQuery這一個工程。我認爲OP沒有假設他使用它。 :) – Amessihel