samber / chartjs-plugin-datasource-prometheus

📊 Chart.js plugin for Prometheus
https://www.npmjs.com/package/chartjs-plugin-datasource-prometheus
MIT License
109 stars 20 forks source link

dataSetHook has an error #39

Open pd1drone opened 11 months ago

pd1drone commented 11 months ago

Hello I tried to use the dataSetHook but I am getting an error about

index.umd.ts:50 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'forEach')
    at cn (index.umd.ts:50:18)
    at dn (index.umd.ts:50:18)
    at bn.update (index.umd.ts:50:18)
    at An.update (index.umd.ts:50:18)
    at Object.resumeRendering (prometheus-query.umd.js:7:71)
    at prometheus-query.umd.js:7:71
cn  @   index.umd.ts:50
dn  @   index.umd.ts:50
update  @   index.umd.ts:50
update  @   index.umd.ts:50
resumeRendering @   prometheus-query.umd.js:7
(anonymous) @   prometheus-query.umd.js:7
Promise.catch (async)       
beforeUpdate    @   prometheus-query.umd.js:7
d   @   color.esm.js:97
_notify @   index.umd.ts:50
notify  @   index.umd.ts:50
notifyPlugins   @   index.umd.ts:50
update  @   index.umd.ts:50
An  @   index.umd.ts:50
(anonymous) @   main.js:175

I believe that this is an error on the dataSetHook since when I remove it this error is not showing in the console.

My code for initializing the chart looks like this:

var jitterChart = new Chart(ctxjitter, {
    type: 'line',
    plugins: [ChartDatasourcePrometheusPlugin],
    options: {
      animation: {
        duration: 0,
      },
      plugins: {
        'datasource-prometheus': {
          query: [jitterQuery,maxLatencyQuery],
          timeRange: {
            type: 'absolute',
            start: startDate,
            end: endDate,
            msUpdateInterval: 5000,
          },
          dataSetHook:(datasets) => {
            console.log(datasets);
          },
        },
      },
    },
  });

NOTE: Please correct me if this is an error from my end. thank you.

pd1drone commented 11 months ago

Also would like to add on how do I add a label on the y-axis. I wanted to add a unit into it image