Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                  <nav class="navbar navbar-light bg-light mb-4">
    <div class="container">
      <span class="navbar-brand mb-0 h1">ベランダ気象データ</span>
  <div class="container">

    <div class="button-type border-bottom pb-2 mb-2">
      <button type="button" class="btn btn-outline-primary active" data-mode="airPressure">気圧</button>
      <button type="button" class="btn btn-outline-primary" data-mode="temperature">気温</button>
      <button type="button" class="btn btn-outline-primary" data-mode="humidity">湿度</button>
      <button type="button" class="btn btn-outline-primary" data-mode="batteryVoltage">バッテリー電圧</button>
      <button type="button" class="btn btn-outline-primary" data-mode="solarVoltage">ソーラー電圧</button>
    <div class="period">
      期間 <input type="text" class="form-control d-inline-block datepicker" style="width:150px;" id="date-start">
      〜 <input type="text" class="form-control d-inline-block datepicker" style="width:150px;" id="date-end">

    <canvas id="myChart" width="400" height="400"></canvas>




                var myChart;
var mode = 'airPressure'; // 初期表示:気圧
var weatherData = {};
weatherData.label = {
  'batteryVoltage': 'バッテリー電圧',
  'solarVoltage': 'ソーラー電圧',
  'airPressure': '気圧',
  'temperature': '気温',
  'humidity': '湿度'
weatherData.time = [];
weatherData.batteryVoltage = [];
weatherData.solarVoltage = [];
weatherData.airPressure = [];
weatherData.temperature = [];
weatherData.humidity = []; = [];

// テストデータ
// 2022/1/1から10時間毎の仮データを1000件分作成
function getRandomArbitrary(min, max) {
  return Math.random() * (max - min) + min;
for (var i=1; i<1000; i++) {
  weatherData.time[i] = new Date('2022/1/1').getTime() + (3600000*i);
  weatherData.batteryVoltage[i] = getRandomArbitrary(4,4.15);
  weatherData.solarVoltage[i] = getRandomArbitrary(0.1,10);
  weatherData.airPressure[i] = 1030 - (i/getRandomArbitrary(90,100));
  weatherData.temperature[i] = getRandomArbitrary(0,10);
  weatherData.humidity[i] = getRandomArbitrary(50,80);

function drawMyChart(){
  for (var i = 0; i < weatherData.time.length; i++) {[i] = {
      x: new Date( weatherData.time[i] ),
      y: weatherData[mode][i]
  const ctx = document.getElementById('myChart').getContext('2d');
  if (myChart) {
  myChart = new Chart(ctx, {
    type: 'line',
    data: {
      datasets: [{
        label: weatherData.label[mode],
        fill: false,
        spanGaps: true,
        borderColor: 'rgb(75, 192, 192)',
        tension: 0.1
    options: {
      responsive: true,
      scales: {
        x: {
          type: 'time',
          time: {
            unit: 'day',
          min: weatherData.min,
          max: weatherData.max

// グラフ切替
$('.button-type button').click(function(event) {
  if( !$(this).hasClass('active') ) {
    $('.button-type button').removeClass('active');
    mode =  $(this).data('mode');

// datepicker
  dateFormat: 'yy/mm/dd',
  onSelect: function(dateText, inst){
    var type = $(this).attr('id') == 'date-start' ? 'min' : 'max';
    weatherData[type] = new Date(dateText);
$('.period input').on('input',function(event) {
  if (!$(this).val()) {
    var type = $(this).attr('id') == 'date-start' ? 'min' : 'max';
    weatherData[type] = '';