wrb 0 Posted April 8, 2015 Report 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> Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 8, 2015 Report Share Posted April 8, 2015 Check your developer console for error messages. Don't use "#" as part of the element ID. Quote Link to post Share on other sites
wrb 0 Posted April 8, 2015 Author Report 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> Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 8, 2015 Report 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? Quote Link to post Share on other sites
wrb 0 Posted April 8, 2015 Author Report 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. Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 8, 2015 Report Share Posted April 8, 2015 It sounds like everything is working then, is there still a problem? Quote Link to post Share on other sites
wrb 0 Posted April 8, 2015 Author Report 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... Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 8, 2015 Report 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? Quote Link to post Share on other sites
wrb 0 Posted April 8, 2015 Author Report Share Posted April 8, 2015 Yes, when the select has only one item. Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 9, 2015 Report 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.