0
我正在使用canvasjs繪製柱形圖。我使用的代碼從這個鏈接https://canvasjs.com/editor/?id=https://canvasjs.com/example/gallery/column/oil_reserves/,代碼如下:如何使用canvasjs使用文本數據繪製柱形圖
<!DOCTYPE HTML>
<html>
<head>
<title>Basic HTML5 Column Chart </title>
<script type="text/javascript">
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Top Oil Reserves"
},
animationEnabled: true,
axisY: {
title: "Reserves(MMbbl)"
},
legend: {
verticalAlign: "bottom",
horizontalAlign: "center"
},
theme: "theme2",
data: [
{
type: "column",
showInLegend: true,
legendMarkerColor: "grey",
legendText: "MMbbl = one million barrels",
dataPoints: [
{y: 297571, label: "Venezuela"},
{y: 267017, label: "Saudi" },
{y: 175200, label: "Canada"},
{y: 154580, label: "Iran"},
{y: 116000, label: "Russia"},
{y: 97800, label: "UAE"},
{y: 20682, label: "US"},
{y: 20350, label: "China"}
]
}
]
});
chart.render();
}
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</head>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;">
</div>
</body>
</html>
現在我想用在Python,而不是在數據點的默認值生成一個文本文件。測試文件數據看起來像逗號分隔的字典數據。這裏是文本文件數據的樣本:
{'DNS_SERVER1': 2.768651, 'FTP_SERVER1': 2.488129, 'AUTHENTICATION_SERVER1': 2.768651, 'WAP_SERVER1': 2.768651, 'WEB_SERVER1': 2.768651, 'EMAIL_SERVER1': 2.768651}
我想要的標籤,像「DNS_SERVER1」和y的值等於像2.768651分號的第二部分分號之前第一部分。我如何使用canvasjs腳本來做到這一點?任何幫助表示讚賞。
謝謝。
我該怎麼做?假設我有一個帶有以下數據的文本文件:{'DNS_SERVER1':2.768651,'FTP_SERVER1':2.488129,'AUTHENTICATION_SERVER1':2.768651,'WAP_SERVER1':2.768651,'WEB_SERVER1':2.768651,'EMAIL_SERVER1':2.768651},從這個角度來看,如何使數據像你的?沒有任何方法可以將文本文件內容解析爲json數據嗎?因爲我看到一個可以使用代碼的例子,如果我可以從文本文件解析數據爲json。 – Arif
這裏是一個例子http://jsfiddle.net/canvasjs/RxeP6/ – Arif
http://stackabuse.com/reading-and-writing-json-to-a-file-in-python/ –