我正在用 asp.net C# 创建图表,准备 JSON 字符串格式的图表数据, 并将 JSON 发送到 Java Script 以进行图表渲染
我在后面的 C# 代码中准备了 JSON,然后将其发送到 Java 脚本
这是我的 JSON
{
"chart":{
"theme":"carbon",
"valueFontColor":"000000",
"rotateValues":"0"
},
"data":[
{
"label":"AN INTEGRATED SYSTEMS LLC",
"value":"859050",
"link":"newchart-json-AN INTEGRATED SYSTEMS LLC"
},
{
"label":"BAHAN N",
"value":"623295",
"link":"newchart-json-BAHAN N"
}
],
"linkeddata":[
{
"id":"CO TA L.L.C.",
"linkedchart":{
"chart":{
"captionLinkedChart":"",
"theme":"carbon"
},
"data":[
{
"label":"AN INTEGRATED SYSTEMS LLC",
"value":"859050"
},
{
"label":"Total",
"value":"41722065"
}
]
}
}
]
}
这是我调用 JSON 的脚本
<script>
var json = '<%=jsonString%>';
FusionCharts.ready(function() {
var satisfactionChart = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '400',
height: '300',
dataFormat: 'json',
dataSource: json,
});
</script>
public partial class MYPAGE: System.Web.UI.Page
{
public string jsonString = "";
protected void Page_Load(object sender, EventArgs e)
{
jsonString = SendJson();
}
和SendJson();将从 SQL 中获取数据并准备 JSON 格式