Jump to content

The select changed and now?


wrb

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...