asp 用fusionchart做图表,怎么读取access数据库中的数据用到fusionchart中?
发布网友
发布时间:2022-07-20 21:59
我来回答
共1个回答
热心网友
时间:2023-10-24 07:56
第一步:用asp连接access查询数据表中的数据。
第二步:根据fusionchart 调用的js文件中的"data": [{..}]部分,按照固定格式输出;
此步骤是关键,就是按照fusionchart 要求输出即可,有两种方法,1是在当前HTML页面中直接通过asp的 response.write(rs("value"));输出数据库内容。2是输出内容以后保存js文档,供html调用。
第三步:正常调用fusionchart 输出图表;
举例子:
FusionCharts.ready(function () {
var revenueChart = new FusionCharts({
type: 'doughnut2d',
renderAt: 'chart-container',
width: '450',
height: '450',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Split of Revenue by Proct Categories",
"subCaption": "Last year",
"numberPrefix": "$",
"paletteColors": "#0075c2,#1aaf5d,#f2c500,#f45b00,#8e0000",
"bgColor": "#ffffff",
"showBorder": "0",
"use3DLighting": "0",
"showShadow": "0",
"enableSmartLabels": "0",
"startingAngle": "310",
"showLabels": "0",
"showPercentValues": "1",
"showLegend": "1",
"legendShadow": "0",
"legendBorderAlpha": "0",
"defaultCenterLabel": "Total revenue: $64.08K",
"centerLabel": "Revenue from $label: $value",
"centerLabelBold": "1",
"showTooltip": "0",
"decimals": "0",
"captionFontSize": "14",
"subcaptionFontSize": "14",
"subcaptionFontBold": "0"
},
"data": [
//原js文件中的格式要求部分
//{
// "label": "Food",
// "value": "28504"
//},
//{
// "label": "Apparels",
// "value": "14633"
//},
//{
// "label": "Electronics",
// "value": "10507"
//},
//{
// "label": "Household",
// "value": "4910"
//}
//注意这里开始用asp输出
<%
for i=1 to rs.recordcount
if rs.eof then exit for
if i<rs.recordcount then
response.write("{"label":" & rs("name") & ",")
response.write(""value":") & rs("value") & "},")
else
response.write("{"label":" & rs("name") & ",")
response.write(""value":") & rs("value") & "}")
end if
rs.movenext:next
%>
]
}
}).render();
});