Jump to content

The select changed and now?


Recommended Posts

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 post
Share on other sites
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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...