Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am unable to show data provided from database in the google chart. I am constantly getting the same error in chrome console.

What I have tried:

JavaScript
@model  IEnumerable<business_entities.traineesearch>

google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawDualY);

function drawDualY() {
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Topic');
      data.addColumn('string', 'Test');
      data.addColumn('string', 'Retest');

    
          @foreach (var item in Model)
			{
			    @: data.addRows[{@item.TTopic},@item.TScoreTest,@item.TScoreRetest],
			}
        
      var options = {
        chart: {
          title: 'Employee Score Card',
          
        },
        series: {
          0: {axis: ''},
          1: {axis: ''}
        },
        axes: {
          y: {
            MotivationLevel: {label: 'Test Score'},
            EnergyLevel: {label: 'Restest Score'}
          }
        },
        hAxis: {
          title: 'Test Topic',
          format: '',
          viewWindow: {
            min: [9, 30, 0],
            max: [17, 30, 0]
          }
        },
        vAxis: {
          title: 'Employee Score'
        }
      };

      var materialChart = new google.charts.Bar(document.getElementById('chart_div'));
      materialChart.draw(data, options);
}
    
<div id="chart_div" style="height: 40%; width: 40%"></div>
Posted
Updated 1-Jul-17 23:10pm
v2
Comments
Richard Deeming 4-Jul-17 12:45pm    
Which line of the code does the error point you to?

And what does the rendered version of that line look like?

If I had to guess, I'd be very suspicious of the line:
@: data.addRows[{@item.TTopic},@item.TScoreTest,@item.TScoreRetest],
I suspect the square brackets should be round brackets, and the curly brackets shouldn't be there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900