picasso.chart({
element: document.querySelector('#container'),
data,
settings: {
scales: {
y: {
data: {
fields: [
{ field: 'Sales' },
{ source: 'forecast', field: 'SalesUpper' },
{ source: 'forecast', field: 'SalesLower' }
]
},
invert: true,
expand: 0.2
},
t: {
data: {
extract: [{ field: 'Year' }, { field: 'Year', source: 'forecast' }]
}
}
},
components: [
{
type: 'axis',
dock: 'left',
scale: 'y',
formatter: {
type: 'd3-number',
format: '$,.1r'
}
},
{
type: 'axis',
dock: 'bottom',
scale: 't',
formatter: {
type: 'd3-time',
format: '%Y-%m'
}
},
{
key: 'lines',
type: 'line',
data: {
extract: {
field: 'Year',
props: {
v: { field: 'Sales' }
}
}
},
settings: {
coordinates: {
major: { scale: 't' },
minor: { scale: 'y', ref: 'v' }
},
layers: {
line: {}
}
}
},
{
key: 'lines-forecast-area',
type: 'line',
data: {
extract: {
field: 'Year',
source: 'forecast',
props: {
low: { field: 'SalesLower' },
high: { field: 'SalesUpper' }
}
}
},
settings: {
coordinates: {
major: { scale: 't' },
minor0: { scale: 'y', ref: 'low' },
minor: { scale: 'y', ref: 'high' }
},
layers: {
line: {
show: false
},
area: {
fill: 'green',
opacity: 0.2
}
}
}
},
{
key: 'lines-forecast',
type: 'line',
data: {
extract: {
field: 'Year',
source: 'forecast',
props: {
v: { field: 'Sales' }
}
}
},
settings: {
coordinates: {
major: { scale: 't' },
minor: { scale: 'y', ref: 'v' }
},
layers: {
line: {
stroke: 'green',
strokeDasharray: '2 4'
}
}
}
}
]
}
})