I have webmethod and jquery for display chart in pop up for this .. so when i click on search button when there is data then working fine but when there is no data i want to display message "NO Data" in label .. and also pop must not display when there is no data how i do this ..
What I have tried:
check i try this code
[WebMethod]
public static string GetVo(DateTime fromdate, DateTime todate, string region)
{
string data2 = "[";
try
{
T1 DB = new T1();
var rea = (from vv in DB.tblVeh
join rv in DB.tblRen vv.MID equals rv.ID
join re in DB.tblRei on rv.RID equals re.RID
where
re.Region == region
&& (vv.Name != "")
&& re.StartDate >= fromdate
&& re.EndDate <= todate
group vv by vv.Name into g
select new
{
Name = g.Key,
cnt = g.Select(t => t.Name).Count()
}).ToList();
data2 += rea.ToList().Select(x => @"[""" + x.Name + @"""," + x.cnt + "]")
.Aggregate((a, b) => a + "," + b);
data2 += "]";
}
catch (Exception ex)
{
throw new Exception();
}
return data2;
}
and jquery
<script type="text/javascript">
var strarr = [["h", 9], ["t", 3], ["y", 1],["y (bunch)", 1]];
$(function () {
$('[ID*=search_data]').on('click', function () {
var fromdate = $('[ID*=fromdate]').val();
var todate = $('[ID*=todate]').val();
var region = $('[ID*=regiondrop] option:selected')
[0].value;
var obj = {};
obj.fromdate = fromdate;
obj.todate = todate;
obj.region = region;
Getdata(obj);
return false;
});
});
function Getdata(obj) {
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetVo",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (result) {
strarr = result.d;
var myarr = strarr;
Drewchart(myarr);
},
error: function (error) {
alert("error");
}
});
}
function Drewchart(result) {
console.log(JSON.stringify(result, null, 2));
$('#container').highcharts({
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Contents of Charts'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
series: [{
name: 'Delivered amount',
data: JSON.parse(result)
}]
});
}
</script>
<div id="divcontainer" style="display: none" align = "center">
<div id="container" class="cont_charts">
</div>
and for pop up
<script type="text/javascript" >
$(function () {
$("#divcontainer").dialog({
modal: true,
autoOpen: false,
title: "Chart",
width: 600,
height: 450
});
$("#search_data").click(function () {
$("#divcontainer").dialog('open');
});
});
</script>