Skip to content

Instantly share code, notes, and snippets.

@burtyish
Last active August 29, 2015 14:04
Show Gist options
  • Save burtyish/31cfe7730e5825f702a1 to your computer and use it in GitHub Desktop.
Save burtyish/31cfe7730e5825f702a1 to your computer and use it in GitHub Desktop.
Chart.js configuration
chart_options: (data)->
min = Math.min 0,data...
max = Math.max data...
num_of_y_ticks = 5
scale_minmax_rounding_factor = if max > 10000 then 1000 else 500
y_scale_rounding_factor = if max > 10000 then 5000 else 1000
scale_max = scale_minmax_rounding_factor * Math.round(max/scale_minmax_rounding_factor)
scale_min = scale_minmax_rounding_factor * Math.round(min/scale_minmax_rounding_factor)
y_scale_step_size = (scale_max - scale_min) / (num_of_y_ticks)
y_scale_step_rounded = y_scale_rounding_factor * Math.round(y_scale_step_size / y_scale_rounding_factor)
num_of_y_ticks++ if y_scale_step_rounded < y_scale_step_size # If the scale step size was decreased, we need to add a step
showTooltips: true
responsive: true
scaleLabel: "£<%=value%>"
scaleShowGridLines : false
scaleOverride: true
scaleSteps: num_of_y_ticks
scaleStepWidth: y_scale_step_rounded
scaleStartValue: scale_min # Allow for negative values
pointHitDetectionRadius : 3
pointDot : false
onAnimationComplete: _.debounce($.proxy(@_animated_chart, @), 50, true)
onAnimationProgress: _.debounce($.proxy(@_animated_chart, @), 50, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment