Intermittent Chart.js 3.7.1 Graph Distortion on Load

39 views Asked by At

enter image description hereI'm encountering an intermittent rendering issue with Chart.js (version 3.7.1) where the graph occasionally displays with distortions. This problem does not happen consistently; however, when it does, the chart appears with skewed axes or the plotted lines are not rendered correctly. The issue seems to occur randomly upon page load and affects the chart's visual integrity.

{
  "type": "line",
  "data": {
    "labels": [
      "2023-07-04",
      "2023-09-30"
    ],
    "datasets": [
      {
        "type": "line",
        "data": [
          {
            "x": "2023-07-04T00:00:00.000Z",
            "y": 12
          },
          {
            "x": "2023-09-30T00:00:00.000Z",
            "y": 27
          }
        ],
        "borderColor": "#2f53d7",
        "borderDash": [
          10,
          10
        ],
        "borderWidth": 1,
        "xAxisID": "x2",
        "backgroundColor": {},
        "label": "Expected progress"
      },
      {
        "data": [
          {
            "x": "2023-07-04T00:00:00.000Z",
            "y": 12,
            "z": 12
          },
          {
            "x": "2023-07-10T18:30:00.000Z",
            "y": 14,
            "z": 13.245077730429292
          },
          {
            "x": "2023-07-24T18:30:00.000Z",
            "y": 15,
            "z": 15.63150055239899
          },
          {
            "x": "2023-08-21T18:30:00.000Z",
            "y": 18,
            "z": 20.40430082070707
          }
        ],
        "type": "line",
        "pointBorderColor": "#ffffff",
        "borderColor": "#a2a5b1",
        "xAxisID": "x2",
        "pointRadius": 4,
        "borderWidth": 1.5,
        "label": "Actual progress",
        "fill": false
      },
      {
        "type": "line",
        "data": [
          {
            "x": "2023-08-21T18:30:00.000Z",
            "y": 18,
            "z": 20.4,
            "isExpectedValueLine": true
          },
          {
            "x": "2023-08-21T18:30:00.000Z",
            "y": 20.4,
            "z": 20.4,
            "isExpectedValueLine": true
          }
        ],
        "borderColor": "#f9b312",
        "borderDash": [
          10,
          10
        ],
        "borderWidth": 1,
        "xAxisID": "x2",
        "pointBackgroundColor": "#f9b312",
        "backgroundColor": "#fff",
        "pointBorderColor": "#ffffff",
        "label": "Expected progress",
        "pointRadius": 4
      }
    ]
  },
  "options": {
    "title": {
      "display": true,
      "text": "%first time users repeat",
      "position": "left",
      "fontSize": 14,
      "fontColor": "#6d6c6f",
      "fontFamily": "'IBM Plex Sans',sans-serif",
      "fontStyle": "normal",
      "lineHeight": 1.43
    },
    "responsive": true,
    "scales": {
      "x": {
        "axis": "x",
        "display": true,
        "ticks": {
          "source": "data",
          "minRotation": 0,
          "maxRotation": 50,
          "mirror": false,
          "textStrokeWidth": 0,
          "textStrokeColor": "",
          "padding": 3,
          "display": true,
          "autoSkip": true,
          "autoSkipPadding": 3,
          "labelOffset": 0,
          "minor": {},
          "major": {},
          "align": "center",
          "crossAlign": "near",
          "showLabelBackdrop": false,
          "backdropColor": "rgba(255, 255, 255, 0.75)",
          "backdropPadding": 2,
          "color": "#666"
        },
        "grid": {
          "display": false,
          "color": "#979797",
          "drawTicks": true,
          "drawOnChartArea": false,
          "borderColor": "#979797",
          "lineWidth": 1,
          "drawBorder": true,
          "tickLength": 8,
          "offset": false,
          "borderDash": [],
          "borderDashOffset": 0,
          "borderWidth": 1
        },
        "type": "category",
        "offset": false,
        "reverse": false,
        "beginAtZero": false,
        "bounds": "ticks",
        "grace": 0,
        "title": {
          "display": false,
          "text": "",
          "padding": {
            "top": 4,
            "bottom": 4
          },
          "color": "#666"
        },
        "id": "x",
        "position": "bottom"
      },
      "x2": {
        "axis": "x",
        "position": "bottom",
        "display": false,
        "type": "time",
        "grid": {
          "display": false,
          "color": "rgba(173, 173, 174, 0.08)",
          "drawTicks": true,
          "drawOnChartArea": false,
          "lineWidth": 1,
          "drawBorder": true,
          "tickLength": 8,
          "offset": false,
          "borderDash": [],
          "borderDashOffset": 0,
          "borderWidth": 1,
          "borderColor": "rgba(0,0,0,0.1)"
        },
        "bounds": "data",
        "adapters": {},
        "time": {
          "parser": false,
          "unit": false,
          "round": false,
          "isoWeekday": false,
          "minUnit": "millisecond",
          "displayFormats": {
            "datetime": "MMM D, YYYY, h:mm:ss a",
            "millisecond": "h:mm:ss.SSS a",
            "second": "h:mm:ss a",
            "minute": "h:mm a",
            "hour": "hA",
            "day": "MMM D",
            "week": "ll",
            "month": "MMM YYYY",
            "quarter": "[Q]Q - YYYY",
            "year": "YYYY"
          }
        },
        "ticks": {
          "source": "auto",
          "major": {
            "enabled": false
          },
          "minRotation": 0,
          "maxRotation": 50,
          "mirror": false,
          "textStrokeWidth": 0,
          "textStrokeColor": "",
          "padding": 3,
          "display": true,
          "autoSkip": true,
          "autoSkipPadding": 3,
          "labelOffset": 0,
          "minor": {},
          "align": "center",
          "crossAlign": "near",
          "showLabelBackdrop": false,
          "backdropColor": "rgba(255, 255, 255, 0.75)",
          "backdropPadding": 2,
          "color": "#666"
        },
        "offset": false,
        "reverse": false,
        "beginAtZero": false,
        "grace": 0,
        "title": {
          "display": false,
          "text": "",
          "padding": {
            "top": 4,
            "bottom": 4
          },
          "color": "#666"
        },
        "id": "x2"
      },
      "y": {
        "axis": "y",
        "ticks": {
          "maxTicksLimit": 6,
          "color": "#979797",
          "minRotation": 0,
          "maxRotation": 50,
          "mirror": false,
          "textStrokeWidth": 0,
          "textStrokeColor": "",
          "padding": 3,
          "display": true,
          "autoSkip": true,
          "autoSkipPadding": 3,
          "labelOffset": 0,
          "minor": {},
          "major": {},
          "align": "center",
          "crossAlign": "near",
          "showLabelBackdrop": false,
          "backdropColor": "rgba(255, 255, 255, 0.75)",
          "backdropPadding": 2
        },
        "grid": {
          "display": true,
          "color": "#f8f8fa",
          "drawTicks": true,
          "drawOnChartArea": true,
          "borderColor": "#979797",
          "tickColor": "#979797",
          "lineWidth": 1,
          "drawBorder": true,
          "tickLength": 8,
          "offset": false,
          "borderDash": [],
          "borderDashOffset": 0,
          "borderWidth": 1
        },
        "type": "linear",
        "display": true,
        "offset": false,
        "reverse": false,
        "beginAtZero": false,
        "bounds": "ticks",
        "grace": 0,
        "title": {
          "display": false,
          "text": "",
          "padding": {
            "top": 4,
            "bottom": 4
          },
          "color": "#666"
        },
        "id": "y",
        "position": "left"
      }
    },
    "plugins": {
      "legend": {
        "display": false
      },
      "tooltip": {
        "enabled": true,
        "mode": "nearest",
        "intersect": true,
        "xPadding": 12,
        "yPadding": 10,
        "titleFontFamily": "'IBM Plex Sans',sans-serif",
        "bodyFontFamily": "'IBM Plex Sans',sans-serif",
        "titleSpacing": 6,
        "bodySpacing": 6,
        "titleFontSize": 12,
        "bodyFontSize": 11,
        "callbacks": {}
      }
    },
    "layout": {
      "padding": {
        "left": 0,
        "right": 20,
        "top": 10,
        "bottom": 0
      }
    }
  }
}

new Chart(myChartRef, metricGraphConfig);

I am not able to replicate the issue and need some help on how to fix this?

0

There are 0 answers