截至目前,我已经使用ChartJS成功创建了一个线图。但是我想把它堆积成图。如何使用ChartJS创建堆叠图形
下面是我至今:
define(['backbone'], function(Backbone)
{
var fifthSubViewModel = Backbone.View.extend(
{
template: _.template($('#myChart5-template').html()),
render: function(){
$(this.el).html(this.template());
var ctx = this.$el.find('#lineChart5')[0];
var lineChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
datasets: [{
label: "Unavailable Unit",
backgroundColor: "rgba(38, 185, 154, 0.31)",
borderColor: "rgba(38, 185, 154, 0.7)",
pointBorderColor: "rgba(38, 185, 154, 0.7)",
pointBackgroundColor: "rgba(38, 185, 154, 0.7)",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointBorderWidth: 1,
data: this.model.attributes.unavailThisYear
}, {
label: "Vacant Unit",
backgroundColor: "rgba(3, 88, 106, 0.3)",
borderColor: "rgba(3, 88, 106, 0.70)",
pointBorderColor: "rgba(3, 88, 106, 0.70)",
pointBackgroundColor: "rgba(3, 88, 106, 0.70)",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(151,187,205,1)",
pointBorderWidth: 1,
data: this.model.attributes.vacThisYear
}]
},
options: {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Income in $'
}
}]
}
}
});
},
initialize: function(){
console.log("In the initialize function");
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destroy', this.remove);
this.render();
}
});
return fifthSubViewModel;
});
目前,我一个图表上获得两个线图。但我不知何故想让它们堆叠起来。我的意思是第二条线图的起点应该是第一条线图所在的地方。所以,该地区不应该重叠。有没有什么办法可以告诉我的折线图,从另一个折线图结束的值开始,以便得到一个堆积图。
当前屏幕截图不能堆叠:
你试过设置堆叠:真正旁边的scaleLabel财产? – juvian
不,我是新手,所以我不知道。 – Unbreakable
是否可以在两个折线图配置中都放置scaleLabel:true?请指导 – Unbreakable