我正在使用javascript生成简单的条形图。我想让酒吧上涨而不是下跌。我怎样才能做到这一点?
请注意,mainContainer在HTML中引用了div,而我仅使用javascript添加样式。
var sampleData = [2, 8, 4, 5, 7, 3];
var mainContainer = document.querySelector(".graphite-container");
var addColumns = function(data) {
for (i = 0; i < data.length; i++) {
var column = document.createElement("div");
column.className = "graphite-column";
column.Id = 'column-' + (i + 1);
column.innerHTML = column.Id;
var columnValue = '';
columnValue += (data[i] * 25) + 'px';
$(column).css({
"display": "inline-block",
"height": columnValue,
"background-color": "blue"
});
$(mainContainer).append(column);
}
};
addColumns(sampleData);
最佳答案
您需要将vertical-align:bottom;
设置为列。
var sampleData = [2, 8, 4, 5, 7, 3];
var mainContainer = document.querySelector(".graphite-container");
var addColumns = function(data) {
for (i = 0; i < data.length; i++) {
var column = document.createElement("div");
column.className = "graphite-column";
column.Id = 'column-' + (i + 1);
column.innerHTML = column.Id;
var columnValue = '';
columnValue += (data[i] * 25) + 'px';
$(column).css({
"display": "inline-block",
"height": columnValue,
"background-color": "blue",
"vertical-align": "bottom"
});
$(mainContainer).append(column);
}
};
addColumns(sampleData);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="graphite-container"></div>
关于javascript - CSS“高度”值是向下而不是向上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50341616/