Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have the below code in code behind.

      protected void Page_Load(object sender, EventArgs e)  
       {    
         hdndata.Value = ShowFusionChart();    
       }  

      public string ShowFusionChart()  
       { 
        DataTable dt = new DataTable();     
        dt = LoadGrid();  
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();   
        List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row;    

        foreach (DataRow dr in dt.Rows)        
         { 
         row = new Dictionary<string, object>(); 
         foreach (DataColumn col in dt.Columns) 
           {  
         if (col.ColumnName.ToLower() == "linkname")  
             row.Add("label", dr[col]);  
         if (col.ColumnName.ToLower() == "countno") 
             row.Add("value", dr[col]); 
        } 
        rows.Add(row);  
      }   
       return serializer.Serialize(rows); 
    }  

    Public DataTable LoadGrid()  
     {  
     // This code block is generating a DataTable from database 
     } 

I am having the below sample data into my hiddenfield 'hdndata' as

[{"label":"Products","value":88},{"label":"Documents","value":77},{"label":"Videos","value":58}]  

At the Design Page ......

 <div id="chartContainer">FusionCharts XT will load here!</div>   
 <div id="chartContainer2"></div>   


<script type="text/javascript" src="fusioncharts/fusioncharts.js"></script>  
<script type="text/javascript" src="fusioncharts/themes/fusioncharts.theme.zune.js"></script>  

<script type="text/javascript">  

   $(function () {    
 `enter code here`  
    alert($('#hdndata').val());// getting alert with Json Data.  
    FusionCharts.ready(function () {       

    var jdata ;  
    jdata = $('#hdndata').val();  
    //console.log(jdata);    

           var revenueChart = new FusionCharts({  
            type: "column2d",  
            renderAt: "chartContainer",  
            width: "500",  
            height: "300",  
            dataFormat: "json",  
            dataSource: {   
                "chart": {   
                    "caption": "Asset Tracking Report",   
                    "subCaption": "Microsite Report",   
                    "xAxisName": "Assets",   
                    "yAxisName": "Count",   
                    "theme": "zune"   
                },   
                "data": jdata   
            }   
        });    
        revenueChart.render("chartContainer");   

    });   
    });    


</script>    

Still the Chart is not populated. No Error is showing. The message is 'No Data found to display'.

If I provide the static Json format data after "data": then that works perfectly.

My Question is how to run the chart with dynamic data? Please help me to find my mistakes. Thank you All.

share|improve this question

1 Answer 1

Please note that if your chart shows a "No data to display" message, it could be that your data doesn't contain any data that could be plotted by FusionCharts XT or incorrect data format.

The chart is rendered correctly by passing the data in the "jdata" variable appended to the JSON, as we had tested your code.

It seems the issue might be caused while fetching the data from the database and passing to the chart via "jdata" variable. Please recheck whether the "'$('#hdndata').val();" code is generating the correct data that needs to be passed to the chart.

share|improve this answer
    
Hi Sanjukta, If I pass the Json data in the data part of chart, then chart is preparing perfectly. Also, I have checked that the hiddenfiled is geeting filled with the JSON data from database, I can see the value of hiddenfield from this line of code. alert($('#hdndata').val()); – Subrata Chakraborty Mar 26 at 8:39
1  
I have converted the data into JSON and then used the variable into chart. jdata = JSON.parse($('#hdndata').val()); That works. Thank all. – Subrata Chakraborty Mar 26 at 9:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.