javascript - 我的代码有什么问题? javascript图表位置

标签 javascript css html5-canvas chart.js

我正在尝试将我的两个 Chart.js 设置为水平位置。但不幸的是我的两个图表 div 没有响应样式。有谁知道我的代码有什么问题。

   <style>
    #Bar {
        position: absolute;
        left: 0px;
        right: 0px;
        bottom: 0px;
        top: 0px;
    }

   #Pie {
        position: absolute;
        left: 500px;
        right: 0px;
        bottom: 0px;
        top: 0px;
    }
</style>



<div class="Bar">

    <label for="myChart">
        Bar chart Title <br />
        <canvas id="myChart" width="300" height="250"></canvas>
    </label>
</div>


<div class="Pie">
    <label for="myPieChart">
        Pie chart Title<br />
        <canvas id="myPieChart" width="250" height="250"></canvas>
    </label>
</div>

enter image description here

最佳答案

您使用 css id(#) 选择器,但您的 div 上有 class(.)es。将 classes 更改为 ids。

<div id="Bar">

    <label for="myChart">
        Bar chart Title <br />
        <canvas id="myChart" width="300" height="250"></canvas>
    </label>
</div>


<div id="Pie">
    <label for="myPieChart">
        Pie chart Title<br />
        <canvas id="myPieChart" width="250" height="250"></canvas>
    </label>
</div>

或者将样式的选择器更改为类(使用 .)。

.Bar {
    position: absolute;
    left: 0px;
    right: 0px;
    bottom: 0px;
    top: 0px;
}

.Pie {
    position: absolute;
    left: 500px;
    right: 0px;
    bottom: 0px;
    top: 0px;
}

示例

#Bar {
    position: absolute;
    left: 0px;
    right: 0px;
    bottom: 0px;
    top: 0px;
}

#Pie {
    position: absolute;
    left: 500px;
    right: 0px;
    bottom: 0px;
    top: 0px;
}
<div id="Bar">
    <label for="myChart">
        Bar chart Title <br />
        <canvas id="myChart" width="300" height="250"></canvas>
    </label>
</div>


<div id="Pie">
    <label for="myPieChart">
        Pie chart Title<br />
        <canvas id="myPieChart" width="250" height="250"></canvas>
    </label>
</div>

关于javascript - 我的代码有什么问题? javascript图表位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42090408/

相关文章:

javascript - 在 angularjs 中使用 $http 将 json 文件显示到 View

javascript - 如何使用 Google 电子表格从用户那里获取文本?

html - IE渐变滤镜背景覆盖事件背景色

css - 在 Shiny 中更改选择器输入项的颜色

html - 如何从 <table> 中删除默认空间?

html - box-shadow 在 ie-8 中不工作

iphone - html5 Canvas 游戏 - 如何添加视网膜支持

javascript - $emit 在 angularjs 中将数据从一个 Controller 发送到另一个 Controller 时不起作用

javascript - 如何防止路径再次被填满?

javascript - Jquery 中的变量未在 javascript 中定义