score:1

Accepted answer

you can use reduce function to count for each category. working solution

let res = [...data].reduce(
(a, c) => (a[c.items.selecteditem] = (a[c.items.selecteditem] || 0) + 1, a),{});

use the resulting object in your pie chart as following for labels and data.

labels = object.keys(res);
data = object.values(res));

score:0

i was a bit confused because you have both 'truck' & 'trucks', maybe thats an error in itself. but for your question, here is a solution:

  const a = data.filter((a) => a.items.selecteditem === "car");
  const b = data.filter((b) => b.items.selecteditem === "bikes");
  const c = data.filter((c) => c.items.selecteditem === "motor");
  const d = data.filter((d) => d.items.selecteditem === "truck");
  const e = data.filter((e) => e.items.selecteditem === "trucks");

and when you insert data into the pie:

<pie
    data={{
      labels: ar,
      datasets: [
        {
          data: [a.length, b.length, c.length, d.length, e.length],
          backgroundcolor: ["red", "yellow", "green", "blue", "pink"],
          bordercolor: ["rgba(255, 99, 132, 1)"],
          borderwidth: 1
        }
      ]
    }}
    height={400}
    width={600}
    options={{
      maintainaspectratio: false,
      title: {
        display: true,
        text: "selected",
        fontsize: 20
      },
      legend: {
        labels: {
          fontsize: 25
        }
      }
    }}
  />

Related Query

More Query from same tag