wrb Posted April 8, 2015 Share Posted April 8, 2015 In the code below I need to select an item in the "select" the graphic is rendered, how could implement this? @using (Html.BeginForm()){ @Html.AntiForgeryToken() @Html.ValidationSummary(true)<select id="animais" name="cod_animal" class="form-control"></select><script type="text/javascript"> //google.load('visualization', '1.1', { 'packages': ['corechart'] }); //google.setOnLoadCallback(drawChart); function drawChart() { var frm = document.getElementById('#animais'); var animais = frm.options[frm.selectedIndex].value; var url = '/Programa_Nutricao/Avaliacao/EvolucaoPeso/' + animais; $.get(url, {}, function (data) { var tdata = new google.visualization.DataTable(); tdata.addColumn('date', 'data_semanal'); tdata.addColumn('number', 'peso_kg'); for (var i = 0; i < data.length; i++) { if (data[i].data_semanal != null) tdata.addRow([ToJavaScriptDate(data[i].data_semanal), parseFloat(data[i].peso_kg)]); } var options = { title: 'Evolução do peso corporal', width: 700, height: 500, vAxis: { title: "PESO (kg)", minValue: 1, maxValue: 6 }, hAxis: { title: "DATA", textStyle: { fontSize: 10 } }, legend: { position: "none" } }; var chart = new google.visualization.LineChart(document.getElementById('EvolucaoPeso')); chart.draw(tdata, options); }); }</script> <div id="EvolucaoPeso" style="width: 900px; height: 500px;"></div> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2015 Share Posted April 8, 2015 Check your developer console for error messages. Don't use "#" as part of the element ID. Link to comment Share on other sites More sharing options...
wrb Posted April 8, 2015 Author Share Posted April 8, 2015 I was with an event in select "onchange" as below, but in the select has only one item I not I the desired effect. I need to render the chart being the select filled. <form action=""> @Html.DropDownList("cod_animal", null, new { onchange = "drawchart(this.value)", Name = "cod_animal", id = "cod_animal", @class = "form-control" }) </form> <script type="text/javascript"> google.load('visualization', '1.1', { 'packages': ['corechart'] }); google.setOnLoadCallback(function(){drawchart('')}); function drawchart(cod_animal) { var url = '/Programa_Nutricao/Avaliacao/EvolucaoPeso/' + cod_animal; $.get(url, {}, function (data) { var tdata = new google.visualization.DataTable(); tdata.addColumn('date', 'data_semanal'); tdata.addColumn('number', 'peso_kg'); for (var i = 0; i < data.length; i++) { if (data.data_semanal != null) tdata.addRow([ToJavaScriptDate(data.data_semanal), parseFloat(data.peso_kg)]); } var options = { title: 'Evolução do peso corporal', width: 700, height: 500, vAxis: { title: "PESO (kg)", minValue: 1, maxValue: 6 }, hAxis: { title: "DATA", textStyle: { fontSize: 10 } }, legend: { position: "none" } }; var chart = new google.visualization.LineChart(document.getElementById('EvolucaoPeso')); chart.draw(tdata, options); }); } </script> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2015 Share Posted April 8, 2015 Why change the code? Does that onchange event send the correct value to the function? Are you checking that? Are you verifying that the URL is correct? Link to comment Share on other sites More sharing options...
wrb Posted April 8, 2015 Author Share Posted April 8, 2015 I changed the code because I did not find the error ... The "onchange" sends the value and renders the chart. The URL is correct, it is the place of animals I put 1 for example, the chart is rendered. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2015 Share Posted April 8, 2015 It sounds like everything is working then, is there still a problem? Link to comment Share on other sites More sharing options...
wrb Posted April 8, 2015 Author Share Posted April 8, 2015 See It. The graph is right, the URL this right. The problem is the event when the select receives a graphic value must render. In fact I do not know if the path is with the post code. Lack knowledge in JavaScript... Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2015 Share Posted April 8, 2015 The problem is the event when the select receives a graphic value must render.I don't really understand what you mean. Is there a problem with onchange? Link to comment Share on other sites More sharing options...
wrb Posted April 8, 2015 Author Share Posted April 8, 2015 Yes, when the select has only one item. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 9, 2015 Share Posted April 9, 2015 So you need to verify that the correct value is being sent to that function, and then that the correct URL is being built. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now