1

My requirement is to output 2 y-axis chart with real-time data readings in NodeRED. I have installed ChartJS package in NodeRED and now according to the documentation of the package there should be PATH, Title, X-Axis, Y-Axis, Payload. But I couldn't find the Payload tab anywhere in the Line Chartjs node?

enter image description here

Ref : https://www.npmjs.com/package/node-red-contrib-chartjs

enter image description here

So I assumed that I have to add the code which belonged to Payload inside a function node before the Line Chartjs node.

What I have tried : (my function node)

var left = {payload : msg.payload.readResults[0].v };
var right = {payload : msg.payload.readResults[1].v };


//return [[left,right]];


const labels = [1,2,3,4,5,6,7,8,9,10];
const data = {
  labels: labels,
  datasets: [
    {
      label: 'Dataset 1',
      data: left,
      borderColor: '#ff0000',
      backgroundColor: '#ff0000',
      yAxisID: 'leftCamber',
    },
    {
      label: 'Dataset 2',
      data: right,
      borderColor: '#0000ff',
      backgroundColor: '#0000ff',
      yAxisID: 'rightCamber',
    }
  ]
};

const config = {
  type: 'line',
  data: data,
  options: {
    responsive: true,
    interaction: {
      mode: 'index',
      intersect: false,
    },
    stacked: false,
    plugins: {
      title: {
        display: true,
        text: 'Chart.js Line Chart - Multi Axis'
      }
    },
    scales: {
      leftCamber: {
        type: 'linear',
        display: true,
        position: 'left',
      },
      rightCamber: {
        type: 'linear',
        display: true,
        position: 'right',

        // grid line settings
        grid: {
          drawOnChartArea: false, // only want the grid lines for one axis to show up
        },
      },
    }
  },
};

const actions = [
  {
    name: 'CamberGraph',
    handler(chart) {
      chart.data.datasets.forEach(dataset => {
        dataset.data = chart.data.labels.length
      });
      chart.update();
    }
  },
];


Here I have tried to get the 2 HTTP outputs I've named as left and right as my datasets(2 y-axis) vs hardcoded x-axis(1 through 10) which will be Footage later on.

PS : I have returned the left and right using return statement and it's outputting the values as I expected.

Currently I do not get any output in my debug window as well as in my ChartJS Line Chart when I inject the node. Using what I've tried so far can anybody show where I've done wrong or add/remove anything to make the graph work?

Thank you!

Glenn94
  • 179
  • 1
  • 9

0 Answers0