ChartJS如何提供对象数组作为数据集?

时间:2019-12-04 15:51:43

标签: chart.js

我有一个看起来像这样的数据集;

[
  "transactions": [
    {
      "month": "Dec",
      "data": [
        {
          "id": "333a32c6-eaf0-3f11-8a2b-963282fb700c",
          "amount": "776",
          "created_at": "2019-12-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        },
        {
          "id": "36688452-92f2-3ae7-911a-9543fe29cae6",
          "amount": "1798",
          "created_at": "2019-12-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        },
        {
          "id": "67856ceb-1eb5-369b-b3c1-7bd92c037c70",
          "amount": "9507",
          "created_at": "2019-12-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        },
        {
          "id": "7e9465be-0151-3828-b429-2b7c4db2aa5e",
          "amount": "944",
          "created_at": "2019-12-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        },
        {
          "id": "dd5019b5-690b-33e0-a633-de6162cd687a",
          "amount": "5327",
          "created_at": "2019-12-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        },
        {
          "id": "eb5f1473-e871-357d-be3c-af2dc00ff22d",
          "amount": "4638",
          "created_at": "2019-12-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        }
      ]
    },
    {
      "month": "Mar",
      "data": [
        {
          "id": "5929f7ad-7ad5-35dc-9935-c06bc0283f20",
          "amount": "5251",
          "created_at": "2019-03-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        }
      ]
    },
    {
      "month": "Nov",
      "data": [
        {
          "id": "8c36b5dd-2b15-3024-83f4-551df33d9fcc",
          "amount": "3643",
          "created_at": "2019-11-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        },
        {
          "id": "abcd4af5-7a7e-3a9b-8c02-f251f6724062",
          "amount": "2622",
          "created_at": "2019-11-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        }
      ]
    },
    {
      "month": "Oct",
      "data": [
        {
          "id": "925b5efb-7933-396e-96ab-9473a93009ff",
          "amount": "8674",
          "created_at": "2019-10-04 10:57:50",
          "updated_at": "2019-12-04 10:57:50"
        }
      ]
    }
  ]
]

基本上,我想显示一个图表,其中包含一年中的所有月份,如果交易数组中不存在这些月份,则该图表在该月份仅返回0。

我将如何解析该对象并确保其与图表上的标签完全匹配?文档中的所有示例都使用真正的基本整数作为数据集,没有找到使用对象的示例!

0 个答案:

没有答案