LoginSignup
1
0

More than 3 years have passed since last update.

enebularでアンケート

Last updated at Posted at 2020-04-13

概要

enebularで、アンケートやってみた。

写真

image.png

flow

image.png

サンプルコード


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

function drawChart(b) {
  const data = google.visualization.arrayToDataTable(b);
  const options = {
    title: '割合', 
    is3D: true
  };
  const chart = new google.visualization.PieChart(document.querySelector('#chart'));
  chart.draw(data, options);
}

function put(a) {
  var json = {
    "text": a
  };
  $.ajax({
    type: 'POST',
    url: 'https://ev2-prod-node-red-a4d0ce4a-7ff.herokuapp.com/in',
    dataType: 'json',
    data: json,
    success: function(data) {
      let d1 = 0;
      let d2 = 0;
      for (let i = 0; i < data.length; i++)
      {
        if (data[i].yes == "1") d1++;
        if (data[i].yes == "2") d2++;
      }
      const d = [["接触", "割合"], ["できた", d1], ["できない", d2]];
      drawChart(d);
    },
    error: function(res) {
      alert("err0");
    }
  });
}

function run() {
  if ($('input[name=radio]:checked').val() === '1')
  {
    put("1");
  }
  if ($('input[name=radio]:checked').val() === '2')
  {
    put("2");
  }
}




成果物

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0