首页 > 解决方案 > Bootstrap Carousel:未显示指标,动画不适用于所有幻灯片,更改幻灯片的背景

问题描述

我想在 BS carousel 图表上的代码中显示指标(h3/p 标签)。看起来它不起作用,躲在图表后面。我们如何让它显示?

以下是我需要解决的问题。

  1. 显示指标(h3,p 标签)。
  2. 动画不适用于所有幻灯片,仅适用于活动幻灯片。
  3. 删除幻灯片中的黑色显示并保留白色背景。

下面是我尝试过的指标标签。

<ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>

完整的 HTML 代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
   <script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>google.charts.load('current', { packages: ['corechart'] });</script>
     <script language='JavaScript'>function drawChart(ExecutedCount, NonExecutedCount, DivID) { var data = google.visualization.arrayToDataTable([['Status', 'Outcome', { role: 'style' }], ['Executed', ExecutedCount, '#8BC34A'], ['Not Executed', NonExecutedCount, '#ff4c4c']]); var groupData = google.visualization.data.group(data, [{ column: 0, modifier: function () { return 'total' }, type: 'string' }], [{ column: 1, aggregation: google.visualization.data.sum, type: 'number' }]); var formatPercent = new google.visualization.NumberFormat({ pattern: '#,##0.0%' }); var formatShort = new google.visualization.NumberFormat({ pattern: 'short' }); var view = new google.visualization.DataView(data); view.setColumns([0, 1, 2, { calc: function (dt, row) { var amount = formatShort.formatValue(dt.getValue(row, 1)); var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1)); return amount + ' (' + percent + ')'; }, type: 'string', role: 'annotation' }]); var options = { 'legend': 'none', tooltip: { trigger: 'none' }, 'width': 650, 'height': 400, animation: { duration: 1500, startup: true } }; var chart = new google.visualization.ColumnChart(document.getElementById(DivID)); chart.draw(view, options); } google.charts.setOnLoadCallback(function () { drawChart(70, 5, 'GChart_0'); }); google.charts.setOnLoadCallback(function () { drawChart(80, 10, 'GChart_1'); }); google.charts.setOnLoadCallback(function () { drawChart(90, 15, 'GChart_2'); });</script>
    <link rel='icon' type='Icon.ico' href='Icon.ico' />
</head>
<body>
<div class="container">
  <h2>Carousel Example</h2>
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <!-- Wrapper for slides -->
    <div class="carousel-inner">
      <div align="center" class="item active" id='GChart_0' style='width:800; height:500;border-style:groove;border-width: 1px;'>
      <h3 style="background-color: gold;">Los Angeles</h3>
        <script type='text/javascript'>drawChart(70, 5, 'GChart_0');</script>
         <p background-color: gold;>LA is always so much fun!</p>
      </div>
      <div align="center" class="item" id='GChart_1' style='width:800; height:500;border-style:groove;border-width: 1px;'>
      <h3>NY</h3>
        <script type='text/javascript'>drawChart(80, 10, 'GChart_1');</script>
         <p>NY is always so much fun!</p>
      </div>    
      <div align="center" class="item" id='GChart_2' style='width:800; height:500;border-style:groove;border-width: 1px;'>
      <h3>California</h3>
            <script type='text/javascript'>drawChart(90, 15, 'GChart_2');</script>
             <p>California is always so much fun!</p>
      </div>  
    </div>
    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>
</body>
</html>

指示器应显示提及的位置,动画应适用于所有幻灯片并删除/更改默认幻灯片颜色。请检查和帮助。

标签: htmlchartsgoogle-visualizationcarouselslideshow

解决方案


指标在其位置可用。但由于white指标的原因,它没有显示。

尝试应用以下 CSS。

<style>
  .carousel-indicators li {
    background-color: #ccc !important;
  }
  .carousel-indicators .active {
    background-color: #000 !important;
  }
</style>

您可以在此处查看工作示例 -示例


推荐阅读