gpt4 book ai didi

javascript - FusionCharts 不工作

转载 作者:行者123 更新时间:2023-11-29 10:59:14 26 4
gpt4 key购买 nike

我是整个开发领域的新手。您能帮我找出以下错误吗?我正在将 FusionCharts 用于学校项目,但发现填充图表很困难。我根据提供的教程创建了这些文件,但包含了 MYSQL 元素来检索数据。文件如下,

HTML...

    <!DOCTYPE html>
<html>
<head>
<title>Fusion Charts Column 2D Sample</title>
</head>
<body>
<div id="chart-container">FusionCharts will render here</div>
<script src="js/jquery-2.1.4.js"></script>
<script src="js/fusioncharts.js"></script>
<script src="js/fusioncharts.charts.js"></script>
<script src="js/themes/fusioncharts.theme.zune.js"></script>
<script src="js/app1.js"></script>
</body>
</html>

PHP...

<?php
//address of the server where db is installed
$servername = "localhost";

//username to connect to the db
//the default value is root
$username = "xyz";

//password to connect to the db
//this is the value you would have specified during installation of WAMP stack
$password = "123";

//name of the db under which the table is created
$dbName = "test";

//establishing the connection to the db.
$conn = new mysqli($servername, $username, $password, $dbName);

//checking if there were any error during the last connection attempt
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

//the SQL query to be executed
$query = ("SELECT month, actuallikes, projected, profit FROM avp");

//storing the result of the executed query
$result = $conn->query($query);

//initialize the array to store the processed data
$jsonArray = array();

//check if there is any data returned by the SQL Query
if ($result->num_rows > 0) {
//Converting the results into an associative array
while($row = $result->fetch_assoc()) {
$jsonArrayItem = array();
$jsonArrayItem['lable'] = $row['month'];
$jsonArrayItem['value'] = $row['actuallikes'];
$jsonArrayItem['value1'] = $row['projected'];
$jsonArrayItem['value2'] = $row['profit'];
//append the above created object into the main array.
array_push($jsonArray, $jsonArrayItem);
}
}

//Closing the connection to DB
$conn->close();

//set the response content type as JSON
header('Content-type: application/json');
//output the return value of json encode using the echo function.
echo json_encode($jsonArray);
?>

JavaScript...

var lables = [], values = [], value1s = [], value2s = [];
function getusers() {

$.ajax({
type: 'GET',
async: false,
url: "http://localhost/avp/chart_data.php",
data: {},
dataType: "json",
success: function(result){
if(result){
for(var i = 0 ; i < result.length; i++){
lables.push(result[i].lable);
values.push(result[i].value);
value1s.push(result[i].value1);
value2s.push(result[i].value2);
}
}
},
error: function(errmsg) {
alert("Ajax??????????!"+ errmsg);
}
});
return lables, values, value1s, value2s;
}

getusers();

salesAnlysisChart = new FusionCharts({
type: 'mscombi2d',
renderAt: 'chart-container',
width: '600',
height: '300',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Harry's SuperMart",
"subCaption": "Sales analysis of last year",
"xAxisname": "Month",
"yAxisName": "Amount (In USD)",
"numberPrefix": "$",
"showBorder": "0",
"showValues": "0",
"paletteColors": "#0075c2,#1aaf5d,#f2c500",
"bgColor": "#ffffff",
"showCanvasBorder": "0",
"canvasBgColor": "#ffffff",
"captionFontSize": "14",
"subcaptionFontSize": "14",
"subcaptionFontBold": "0",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"divLineDashLen": "1",
"divLineGapLen": "1",
"showAlternateHGridColor": "0",
"usePlotGradientColor": "0",
"toolTipColor": "#ffffff",
"toolTipBorderThickness": "0",
"toolTipBgColor": "#000000",
"toolTipBgAlpha": "80",
"toolTipBorderRadius": "2",
"toolTipPadding": "5",
"legendBgColor": "#ffffff",
"legendBorderAlpha": '0',
"legendShadow": '0',
"legendItemFontSize": '10',
"legendItemFontColor": '#666666'
},
"categories": [{
"category": lables
}],
"dataset": [{
"seriesName": "Actual Revenue",
"showValues": "1",
"data": values
}, {
"seriesName": "Projected Revenue",
"renderAs": "line",
"data": value1s
}, {
"seriesName": "Profit",
"renderAs": "area",
"data": value2s
}]
}
});
salesAnlysisChart.render(); }
});
});

希望有人能帮助我发现错误。如果我做了任何愚蠢的事情,我深表歉意。

干杯!

最佳答案

您创建的用于呈现图表的 JSON 结构不正确,例如因为“类别”应该有一个对象数组作为值,但您要向它传递一个值数组,数据集中的数据键也是如此。你需要修改你的代码或者你也可以使用我的code .

关于javascript - FusionCharts 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42536026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com