You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0 KiB

class StackedChart extends Chart {
constructor(canvas, data, settings) {
super(canvas, data, settings)
}
draw() {
this.ctx.shadowOffsetX = 15
this.ctx.shadowOffsetY = 15
this.ctx.shadowBlur = 4
let largest = 0
for (let i = 0; i < this.dataLen; i++) {
let sum = 0
this.data.forEach(categ => {
categ.values[i] = Math.abs(categ.values[i])
sum += categ.values[i]
})
largest = sum > largest ? sum : largest
}
this.clear()
this.drawAxis(false)
let size = this.bounds.width / this.dataLen
let bar_width = size * 0.7
for (let i = 0; i < this.dataLen; i++) {
let last_top = this.bounds.xAxis
let num = 0
this.data.forEach((categ, colId) => {
let value = categ.values[i]
let bar_height = value / largest * this.bounds.height
let left = this.bounds.left + size * (i + 0.15)
let top = last_top - bar_height
last_top = top
//x value
if (num === 0) {
let text = (i + 1).toString()
/*if (this.settings.custom_x_values !== "")
text = this.settings.custom_x_values.split(';')[i]*/
this.ctx.beginPath()
this.ctx.font = "16px Arial"
this.ctx.fillStyle = "black"
this.ctx.textAlign = "center"
this.ctx.fillText(text, this.bounds.width / this.dataLen * i + size / 2 + this.bounds.left, this.bounds.bottom + 15)
this.ctx.stroke()
this.ctx.closePath()
}
num++
this.ctx.fillStyle = categ.color
let new_object = new Rectangle(this.ctx, value, colId, left, top, bar_width, bar_height)
new_object.draw()
this.objects.push(new_object)
})
}
}
}

Powered by TurnKey Linux.