简体   繁体   English

如何垂直放置条形图的条形,使其都位于容器的底部?

[英]How can I position bars of a bar chart vertically so they all sit at the bottom of container?

I have produced a dynamically generated bar chart. 我制作了一个动态生成的条形图。 Each bars of the bar chart have different heights. 条形图的每个条形都有不同的高度。 I want to vertically align them all so that they all sit at the bottom of the container div. 我想将它们全部垂直对齐,以便它们都位于容器div的底部。

This is currently how the chart looks; 这是当前图表的外观; the baseline seems to be the top of each bar and it grows downwards. 基线似乎是每个柱线的顶部,并且向下延伸。 I what it to grow upwards like a standard bar chart. 我像标准条形图一样向上增长。

在此处输入图片说明

html: 的HTML:

<div class="chartWrapper">
  <div class="bar" style="height:is-dynamically-generated;"></div>
  <div class="bar" style="height:is-dynamically-generated;"></div>
  <div class="bar" style="height:is-dynamically-generated;"></div>
  etc...
</div>

CSS: CSS:

.bar{
    width:5px;
    border: 1px solid #000;
    background-color:grey;
    float:left;
    margin-left:10px;
}
.chartWrapper{
    width:600px;
    height:600px;
    border: 1px solid #000;
}

So how can I vertically align all the bars so they sit/start at the bottom of the parent div? 那么,如何才能垂直对齐所有条形,使其位于父div的底部/从其开始呢?

.chartWrapper {
    transform: rotate(180deg);
}

I think you can try the following method. 我认为您可以尝试以下方法。

[UPDATED] [更新]

U need to have a bar wrapper for each of the bar. 您需要为每个条形包装一个条形包装纸。 And set the bar wrappers to have the same height as the main wrapper. 并将条形包装纸的高度设置为与主包装纸的高度相同。 Then, set it to have a relative positioning. 然后,将其设置为相对位置。

.barwrapper{
    height: 500px;
    float: left;
    width: 20px;
    position:relative;
    margin-left: 10px;
}

Set the bars to have absolute position, then position them to be always at the bottom of the bar wrapper. 将条设置为绝对位置,然后将其始终放置在条包装纸的底部。

.bar{
    width: 20px;
    position: absolute;
    bottom: 0;
    ...
}

Here's a quick demo I created for this answer. 这是我为此答案创建的快速演示。 http://jsfiddle.net/6M638/ http://jsfiddle.net/6M638/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM