の値を反復処理しようとしています
- oldData.results.bindings.date
- oldData.results.bindings.liability
- oldData.results.bindings.stock
- oldData.results.bindings.event
- oldData.results.bindings.current
...すべての値で。それらをすべて document.write したいと思います (i は oldData.results.bindings.length に「等しい」または「未満」ですが)。出力は次のようになります。
document.write(simpleHead[0] +
'{Date: "' +
oldData.results.bindings[0].date +
'", Liability: ' +
oldData.results.bindings[0].liability +
", Stock: " +
oldData.results.bindings[0].stock +
", " +
oldData.results.bindings[0].event +
": " +
oldData.results.bindings[0].current +
",}" +
simpleTail[0]);
現在、「...[0]...」を使用して出力するデータ セットを 1 つしか取得していませんが(上記のスクリプトを参照)、「...[i ]...'データセットごとに。
現在のコード:
...
function httpGet(theUrl)
{
var xmlHttp = null;
var xmlHttp = null;
xmlHttp = new XMLHttpRequest(); // instantiate request
xmlHttp.open( "GET", theUrl, false ); // open url
xmlHttp.send( null ); // sending nothing
return xmlHttp.responseText; // return url's data as text
};
var result = httpGet("#local#"); // assign this url to the variable name "result"
function revive (key, value) {
if (value.datatype == "http://www.w3.org/2001/XMLSchema#double" || // if datatype is this
value.datatype == "http://www.w3.org/2001/XMLSchema#integer" || // or, this
value.datatype == "http://www.w3.org/2001/XMLSchema#float") // or, this
{
return (parseInt(value.value)) // if '#double', '#integer', or '#schema', then: 'vars' label + convert the datatype's float value to integer
}
else if (value.type == 'literal')
{
return (value.value) // if datatype's value is a literal: 'vars' label + return as a string
}
else if (value.datatype == 'http://www.w3.org/2001/XMLSchema#date')
{
return value.value // if "XMLSchema#date's" value is a literal: 'vars' label + return as a string
}
else
{
return value // if datatype is anything else: 'vars' label + return value as a string
}
};
var scriptHead = ["YUI().use('charts',function(Y){var myDataValues=<br /><br />["];
var scriptTail = ["<br />];<br /><br />var styleDef={series:{Stock:{line:{color:'#EEB647'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#222',alpha:0,wmode:'transparent'},over:{fill:{color:'#eee'},border:{color:'#000'},width:9,height:9}}},Liability:{line:{color:'#171944'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#222',alpha:0,wmode:'transparent'},over:{fill:{color:'#eee'},border:{color:'#000'},width:9,height:9}}},Shipment:{line:{color:'#ff0000',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#ff0000',alpha:0,wmode:'transparent'},over:{fill:{color:'#ff0000',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}},Production:{line:{color:'#FFD700',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#FFD700',alpha:0,wmode:'transparent'},over:{fill:{color:'#FFD700',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}},Order:{line:{color:'#006400',alpha:0,wmode:'transparent'},marker:{fill:{color:'#eee',alpha:0,wmode:'transparent'},border:{color:'#006400',alpha:0,wmode:'transparent'},over:{fill:{color:'#006400',alpha:0,wmode:'transparent'},border:{color:'#000',alpha:0,wmode:'transparent'},width:16,height:16}}}}};var myAxes={dateRange:{keys:['date'],position:'bottom',type:'category',title:'Date Range',styles:{majorTicks:{display:'none'},label:{rotation:-45,margin:{top:5}},title:{fontSize:'90%'}}}};var mychart=new Y.Chart({dataProvider:myDataValues,interactionType:'planar',render:'#mychart',categoryKey:'Date',styles:styleDef,categoryType:'time',horizontalGridlines:{styles:{line:{color:'#fff'}}},verticalGridlines:{styles:{line:{color:'#fff'}}}})});<br /><br />"];
var simpleHead = [scriptHead];
var simpleTail = [scriptTail];
var oldData = JSON.parse(result, revive);
</script>
</head>
<body>
<p>
<script language="JavaScript" type="text/javascript">
// variable? or something here?
for(i=0; i<oldData.results.bindings.length ;i++)
{
document.write(simpleHead[0] + '<br />{Date: "' + oldData.results.bindings[i].date + '", Liability: ' + oldData.results.bindings[i].liability + ", Stock: " + oldData.results.bindings[i].stock + ", " + oldData.results.bindings[i].event + ": " + oldData.results.bindings[i].current + ",}" + simpleTail[0] + "<br /><br />");
}
</script>
</p>
</body>
</html>