转置d3.nest结果的值

时间:2018-12-02 06:05:45

标签: javascript d3.js

我有一个看起来像这样的对象数组

[{center_name:"AXCG", 1_to_2years:34, 3_to_4years:12, 5_to_6years:45},
 {center_name:"BDGT", 1_to_2years:67, 3_to_4years:23, 5_to_6years:45}]

预期结果:

[
  {"key":"AXCG","values":[
    {"interval":'1_to_2years',"value":34},
    {"interval":'3_to_4years',"value":12},
    {"interval":'5_to_6years',"value":45},
  ]},
  {"key":"BDGT","values":[
    {"interval":'1_to_2years',"value":34},
    {"interval":'3_to_4years',"value":12},
    {"interval":'5_to_6years',"value":45},
  ]}]

使用d3.nest之后,我可以将center_names作为键来处理这些值

var nested_data = d3.nest()
.key(function(d) { return d.center_name; })
.entries(output_array);

1 个答案:

答案 0 :(得分:1)

您可以通过各种方式将旧数组转换为新结构。这是其中之一:

final Worker worker = StreamsWorkerFactory
           .createDynamoDbStreamsWorker(
               recordProcessorFactory,
               workerConfig,
               adapterClient,
               amazonDynamoDB,
               amazonCloudWatchClient);