如图
这是我的代码:
1,aspx界面
<div runat="server" visible="false" id="checkActivityReport" style="width: 600px; height: 300px;">
<script type="text/javascript">
var echartsActivity = document.getElementById('checkActivityReport');
var CheckActivity = echarts.init(echartsActivity);
var option = {
title: {
text: '患者近七日的活动时间',
},
xAxis: {
type: 'category',
data: ['第一天', '第二天', '第三天', '第四天', '第五天', '第六天', '第七天']
},
yAxis: {
type: 'value'
},
series: []
};
CheckActivity.setOption(option);
$.ajax({
type: "POST",
async: false,
dataType: "json",
//contentType: "Default.aspx?action=LoadChart"
url:"Default.aspx?action=LoadChart",
beforeSend: function () {
CheckActivity.showLoading(); //显示加载动画效果
},
success: function (obj) {
console.log(obj);
if (obj) {
options.series = obj.series; //给series数据
CheckActivity.hideLoading(); //隐藏动画加载效果
CheckActivity.setOption(options); //设置图表实例的配置项以及数据
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.responseText);
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
</script>
</div>
2.aspx.cs界面
protected void Page_Load(object sender, EventArgs e)
{
string action = Request["action"];
switch (action)
{
case "LoadChart"://查询数据
LoadChart();
break;
default:
break;
}
}
private void LoadChart()
{
List<Series> seriesList = new List<Series>();
Series seriesObj = new Series();
seriesObj.type = "bar"; //柱形
seriesObj.data = new List<int>(); //先初始化 不初始化后面直接data.Add(x)会报错
activitytime = dialySrv.getPatientActivityTime(ddlChooseReportPatient.SelectedValue);
Array.Reverse(activitytime);
for (int i = 0; i <activitytime.Length; i++)
{
seriesObj.data.Add(activitytime[i]);
}
seriesList.Add(seriesObj);
var newObj = new
{
series = seriesList, //series集合
};
string json = JsonConvert.SerializeObject(newObj);
Response.Write(json);
Response.Flush();
Response.Close();
}
public class Series
{
public string type
{
get;
set;
}
// series序列组呈现对应的Y轴刻度
//public int yAxisIndex
//{
// get;
// set;
//}
// series序列组的数据为数据类型数组
public List<int> data
{
get;
set;
}
}
已知activitytime数组为int类型,数组中数据如下:
运行正常,没有弹窗,这要怎么解决呢?