chartjs-plugin-datasource-prometheus icon indicating copy to clipboard operation
chartjs-plugin-datasource-prometheus copied to clipboard

dataSetHook has an error

Open pd1drone opened this issue 2 years ago • 1 comments

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 avatar Nov 02 '23 02:11 pd1drone

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

pd1drone avatar Nov 02 '23 02:11 pd1drone