Skip to content

Instantly share code, notes, and snippets.

@goozler
Created June 26, 2015 08:05
Show Gist options
  • Save goozler/aef858d267de71c44cef to your computer and use it in GitHub Desktop.
Save goozler/aef858d267de71c44cef to your computer and use it in GitHub Desktop.
StaticBars for charts.js (undescore need)
Chart.types.Bar.extend
name: 'StaticBar'
draw: ->
if _.isNumber(@options.barWidth)
datasets = @datasets.length
columns = @datasets[0].bars.length
bars = columns * datasets
barsWidth = bars * @options.barWidth
datasetSpacing = @options.barDatasetSpacing * columns * (datasets - 1)
paddings = @scale.xScalePaddingRight + @scale.xScalePaddingLeft
remainingSpace = @chart.width - barsWidth - datasetSpacing - paddings
if remainingSpace < 0
console.log "Bars don't fit!"
else
@options.barValueSpacing = remainingSpace / (columns * 2)
Chart.types.Bar.prototype.draw.apply(@, arguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment