File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ Chart.register(...registerables);
2222 * @param {Number } yPadding
2323 * @param {Number } xPadding
2424 * @param {Boolean } showCrosshair
25- * @param {CallableFunction } tooltipHandler
26- * @param {CallableFunction } xTicksCallback
25+ * @param {CallableFunction|null } tooltipHandler
26+ * @param {Boolean } hasDateTimeLabels
2727 * @return {Object }
2828 */
2929const CustomChart = (
@@ -39,7 +39,7 @@ const CustomChart = (
3939 xPadding = 10 ,
4040 showCrosshair = false ,
4141 tooltipHandler = null ,
42- xTicksCallback = null
42+ hasDateTimeLabels = false
4343) => {
4444 const themeMode = ( ) => {
4545 if ( theme . mode === "auto" ) {
@@ -315,8 +315,18 @@ const CustomChart = (
315315 } ,
316316 } ;
317317
318- if ( xTicksCallback ) {
319- options . scales . xAxes . ticks . callback = xTicksCallback ;
318+ if ( hasDateTimeLabels ) {
319+ options . scales . xAxes . type = "time" ;
320+ options . scales . xAxes . ticks . maxRotation = 0 ;
321+ options . scales . xAxes . ticks . autoSkipPadding = 10 ;
322+ options . scales . xAxes . time = {
323+ displayFormats : {
324+ hour : "HH:00" ,
325+ day : "dd.MM" ,
326+ month : "MMM yyyy" ,
327+ year : "yyyy" ,
328+ } ,
329+ } ;
320330 }
321331
322332 this . chart = new Chart ( this . getCanvasContext ( ) , { data, options } ) ;
Original file line number Diff line number Diff line change 1313 ' xPadding' => 10 ,
1414 ' showCrosshair' => false ,
1515 ' tooltipHandler' => null ,
16- ' ticksCallback ' => null ,
16+ ' hasDateTimeLabels ' => null ,
1717] )
1818
1919<div
3030 {{ $xPadding } } ,
3131 {{ $showCrosshair ? ' true' : ' false' } } ,
3232 {{ $tooltipHandler ? $tooltipHandler : ' null' } } ,
33- {{ $ticksCallback ? $ticksCallback : ' null ' } }
33+ {{ $hasDateTimeLabels ? ' true ' : ' false ' } },
3434 )"
3535 wire:key =" {{ $id . time () } }"
3636 {{ $attributes -> only (' class' ) } }
You can’t perform that action at this time.
0 commit comments