Explore the API
- .data()
- .bottomAxis.format()
- .bottomAxis.hideAxisLine()
- .bottomAxis.hideTicks()
- .bottomAxis.label()
- .bottomAxis.values()
description
The LeftAxis component represents the left vertical axis of some charts. This example shows the available methods for the component and demonstrates its behavior when various properties of the chart are changed.
code
generate data
function getData () {
const tau = 500 * Math.random() + 500
const lambda = 100 * Math.random() + 50
return [{
name: 'trend',
values: Array.from({ length: 1000 }, (d, i) => ({
x: i / 10,
y: Math.exp(i / tau) * Math.sin(i / lambda) + 10
}))
}]
}
create chart
const chart = dalian.LineChart('myChart', '#widget')
.data(getData())
.width(WIDTH)
.height(HEIGHT)
.margins({left: 60, top: 40, bottom: 40, right: 40})
.font.size(14)
.bottomAxis.label('Elapsed time')
.leftAxis.label('Temperature [C]')
.render()
api methods
let changeData = () => chart.data(getData()).render(1000)
let toggleTickFormat = () => {
this.f = ((this.f || 0) + 1) % 3
chart.leftAxis.format([undefined, x => 10 * x, () => ''][this.f])
.render()
}
let toggleAxisLine = () => {
this.a = 1 - (this.a || 0)
chart.leftAxis.hideAxisLine(this.a).render()
}
let toggleTicks = () => {
this.t = 1 - (this.t || 0)
chart.leftAxis.hideTicks(this.t).render()
}
let toggleLabel = () => {
this.l = ((this.l || 0) + 1) % 3
chart.leftAxis.label(['Temperature [C]', 'Pressure [Pa]', ''][this.l])
.render()
}
let toggleTickValues = () => {
this.v = 1 - (this.v || 0)
chart.leftAxis.values(this.v ? [9, 10, 11] : undefined).render()
}