2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paiza.ioでelixirAdvent Calendar 2022

Day 15

paiza.ioでelixir その90

Last updated at Posted at 2022-11-22

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

散布図を描画せよ。

サンプルコード



IO.puts """
<!doctype html>
<html>
<head>
<style type="text/css">
* {
  margin: 0;
  padding: 0;
  border: 0;
}
body {
  background: #fdd;
  font: 30px sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id='chart'></div>
<textarea id="koko0"> 
"""
for i <- 0..100 do 
    v = :math.sin(i * 440.0 * 2.0 * :math.pi / 20000.0);
    IO.puts(v)
    IO.puts ","
end
IO.puts """
</textarea>
<script type="text/javascript">
google.load("visualization", "1", {
    packages: ["corechart"]
});
var x0 = document.getElementById('koko0').value;
var x = x0.split(",");
var res = [['x', 'sin'],];
for (var i = 0; i < 100; i++)
{
    res.push([i, x[i] / 1]);
}
google.setOnLoadCallback(function() {
    var data = google.visualization.arrayToDataTable(res);    
    var options = {
        title: 'sin波',
        hAxis: {
            title: 'x'
        },
        vAxis: {
            title: 'y'
        }
    };    
    var chart = new google.visualization.ScatterChart(document.getElementById('chart'));
    chart.draw(data, options);
});
</script>
</body>
</html>
"""

実行結果

image.png

成果物

以上。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?