javascript - 全屏 bootstrap 4 卡与 highcharts

标签 javascript jquery highcharts bootstrap-4 fullscreen

我有几张( Bootstrap )卡片,我希望有机会全屏显示。这些卡片中有 Highcharts 图表。问题是当您进入全屏模式时,highcharts 的高度不适应。

不久前,我用引导面板问了同样的问题,然后“daniel_s”为面板做了这个例子。只是现在我在底部添加了一些列,它已经从面板转换为卡片。不幸的是,该示例不再有效。 “daniel_s”又做了一个例子,但高度仍然不是100%。

是否有可能自动调整 Highcharts 的缩放比例,使比率(底部和标题的列)保持与本示例中的相同?

此外,我还想知道我是如何将标题文本和图标放在一行的。这样文本在左边,图标在右边。

HTML

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<!------ Include the above in your HEAD tag ---------->

<div class="container">
  <div class="row">
    <div class="col-md-6 col-lg-3">
      <div class="card with-margin card_shadow card_border rounded">
        <div class="container-fluid" id="mainContainer">
          <div class="row border-bottom-0 card_border2" style="background: linear-gradient(to right, #eea849, #fa7921); justify-content: space-between">
            <h3>Panel 1</h3>
            <li class="list-inline-item"><a href="#" id="panel-fullscreen" class="fullscreen-btn" role="button" title="Toggle fullscreen"><i class="fas fa-expand"></i></a></li>
          </div>
          <div class="row">
            <div class="card-body border-top-0 border-bottom-0 card_border2 row-200">
              <div id="container"></div>
            </div>
          </div>
          <div class="row bg-white justify-content-center card_border">
            <div class="col-sm text-center card_border2">
              <br> text 1
            </div>
            <div class="col-sm text-center card_border2">
              <br> text 2
            </div>
            <div class="col-sm text-center card_border2">
              <br> text 3
            </div>
            <div class="col-sm text-center card_border2">
              <br> text 4
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="col-md-6 col-lg-3">
      <div class="card with-margin card_shadow card_border rounded">
        <div class="container-fluid" id="mainContainer">
          <div class="row border-bottom-0 card_border2" style="background: linear-gradient(to right, #eea849, #fa7921); justify-content: space-between">
            <h3>Panel 2</h3>
            <li class="list-inline-item"><a href="#" id="panel-fullscreen2" class="fullscreen-btn" role="button" title="Toggle fullscreen"><i class="fas fa-expand"></i></a></li>
          </div>
          <div class="row">
            <div class="card-body border-top-0 border-bottom-0 card_border2 row-200">
              <div id="container2"></div>
            </div>
          </div>
          <div class="row bg-white justify-content-center card_border">
            <div class="col-sm text-center card_border2">
              <br> text 1
            </div>
            <div class="col-sm text-center card_border2">
              <br> text 2
            </div>
            <div class="col-sm text-center card_border2">
              <br> text 3
            </div>
            <div class="col-sm text-center card_border2">
              <br> text 4
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

CSS

.panel-actions {
  margin-bottom: 0;
  text-align: right;
}

.panel-actions a {
  color: #333;
}
#mainContainer {
  height: 50%;
}
.panel-fullscreen {
  display: block;
  z-index: 9999;
  position: fixed !important;
  width: 100%;
  height: 100%;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  overflow: auto;
}
.full-height-row {
  height: 100%;
  width: 100%;
}
#container {
  height: 100%;
}
#container2 {
  height: 100%;
}
.row-200 {
  height: 220px;
}

.card_border {
  border: solid 0.75px #fa7921;
}

.card_border2 {
  border: solid 2px #fa7921;
}

JavaScript

$(document).ready(function() {
  var charts = [];
  var chart1Info = {
    containerId: "container",
    definition: {
      title: {
        text: "Chart1 Title"
      },
      subtitle: {
        text: "Source: thesolarfoundation.com"
      },
      yAxis: {
        title: {
          text: "Number of Employees"
        }
      },
      legend: {
        layout: "vertical",
        align: "right",
        verticalAlign: "middle"
      },
      plotOptions: {
        series: {
          label: {
            connectorAllowed: false
          },
          pointStart: 2010
        }
      },
      series: [
        {
          name: "Installation",
          data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
        },
        {
          name: "Manufacturing",
          data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
        },
        {
          name: "Sales & Distribution",
          data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
        },
        {
          name: "Project Development",
          data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
        },
        {
          name: "Other",
          data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
        }
      ]
    }
  };
  var chart2Info = {
    containerId: "container2",
    definition: {
      title: {
        text: "Chart2 Title"
      },
      subtitle: {
        text: "Source: thesolarfoundation.com"
      },
      yAxis: {
        title: {
          text: "Number of Employees"
        }
      },
      legend: {
        layout: "vertical",
        align: "right",
        verticalAlign: "middle"
      },
      plotOptions: {
        series: {
          label: {
            connectorAllowed: false
          },
          pointStart: 2010
        }
      },
      series: [
        {
          name: "Installation",
          data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
        },
        {
          name: "Manufacturing",
          data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
        },
        {
          name: "Sales & Distribution",
          data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
        },
        {
          name: "Project Development",
          data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
        },
        {
          name: "Other",
          data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
        }
      ]
    }
  };

  function drawChart(chartInfo) {
    // Properties that vary by chart should be defined in chartInfo
    // Any properties that are the same for all charts are added here
    chartInfo.responsive = {
      rules: [
        {
          condition: {
            maxWidth: 500
          },
          chartOptions: {
            legend: {
              layout: "horizontal",
              align: "center",
              verticalAlign: "bottom"
            }
          }
        }
      ]
    };

    if (chartInfo == chart1Info) {
      charts[0] = Highcharts.chart(chartInfo.containerId, chartInfo.definition);
    } else {
      charts[1] = Highcharts.chart(chartInfo.containerId, chartInfo.definition);
    }
  }
  //Toggle fullscreen
  $(".fullscreen-btn").click(function(e) {
    e.preventDefault();

    var $this = $(this);
    $this
      .children("i")
      .toggleClass("fa-expand")
      .toggleClass("fa-arrows-alt");
    $(this)
      .closest(".card")
      .toggleClass("panel-fullscreen");
    $($(this).parents()[3])
      .find(".card-body")
      .toggleClass("row-200");

    var chartInfo =
      $this.attr("id") === "panel-fullscreen" ? chart1Info : chart2Info;
    drawChart(chartInfo);
  });

  drawChart(chart1Info);
  drawChart(chart2Info);
});

从这个example可以看出,高度不是100%,而在这个example高度为 100%。我如何管理第一个示例中的高度始终为 100%。

最佳答案

我已经检查了这两个示例并可能找到了解决方案。

  1. 在您的工作示例中,所有元素都位于一个容器 panel 中,该容器的高度设置为 100%,子元素 panel-heading 的高度为 94 %.

  2. 在您的问题示例中,有一个高度设置为 100% 的“卡片”和子 container-fluid,其中 rows 没有固定高度设置。

所以你可以看到行不知道如何共享屏幕上的空间。要修复它,您必须设置 CSS 样式,以便 container-fluid 为 100% 高度和行,例如 10% 顶行、80% 中间行、10% 底行。然后所有元素都正确呈现,如下所示:

enter image description here

关于javascript - 全屏 bootstrap 4 卡与 highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56305200/

相关文章:

jquery - iPhone 移动 Safari : Force keyboard open

javascript - 如何使半圆形 donut chart 居中?

php - 从 PHP、JSON Highcharts 获取数据?

javascript - onBlur 未在 Jest 测试用例、React App 中调用

javascript - 过滤 <td> 元素中带有空格的匹配文本

javascript - 检查电话号码是否可用

javascript - 如何使用 Angular 服务从 API 将数据获取到表中?

javascript - slideDown 立即 li 并向上滑动其他 li 元素

javascript - 在Highcharts中,我们可以在渲染图表之前获取plotWidth和plotHeight吗?