简体   繁体   English

在Pentaho CDE中使用D3图表

[英]Using D3 chart in Pentaho CDE

Hi guys 嗨,大家好

I would like to add this D3 Circle Packing diagram to my Pentaho CDE - http://bl.ocks.org/mbostock/4063530 . 我想将此D3圆包装图添加到我的Pentaho CDE- http://bl.ocks.org/mbostock/4063530

Idea is to use D3 Components Library and add it as D3 Component - put script code as Custom chart script, but I don't know how to do this. 想法是使用D3组件库并将其添加为D3组件-将脚本代码作为“自定义图表脚本”放置,但是我不知道该怎么做。 I only found this tutorial http://biwithui.blogspot.cz/2014/08/d3-chart-in-pentaho-cde.html which is specific for diagram with db datasource. 我只找到本教程http://biwithui.blogspot.cz/2014/08/d3-chart-in-pentaho-cde.html ,该教程特定于具有db数据源的关系图。 My diagram is using json file as input 我的图使用json文件作为输入
d3.json("flare.json"
I believe some of you could help me with: 我相信有些人可以帮助我:
1) how to edit index.html code so I could add it to D3 Component as Custom chart script? 1)如何编辑index.html代码,以便可以将其作为自定义图表脚本添加到D3组件中?
2) how to edit part with flare.json data input, so I could use my own json datasource (with same structure) loaded with Pentaho CDE (probably something like d3.json("#"+this.Datasource ) 2)如何使用flare.json数据输入来编辑零件,因此我可以使用加载了Pentaho CDE的我自己的json数据源(结构相同)(可能类似于d3.json("#"+this.Datasource

Thank you! 谢谢!

You may be confusing the d3.select with d3.json. 您可能将d3.select与d3.json混淆了。 The first picks out the DOM element you want to bind the chart to and the second loads data and takes a callback. 第一个选择要绑定图表的DOM元素,第二个加载数据并进行回调。 Pentaho seems to require you to bind to a hash-tagged element (I'm not familiar with Pentaho, but that seems to be what the guys in the tutorial is doing). Pentaho似乎要求您绑定到带有散列标签的元素(我对Pentaho并不熟悉,但这似乎是本教程中的人正在做的事情)。 Try: 尝试:

//This will load the data into the 'data' variable
d3.json('flare.json', function(data){
    d3.select('#' + this.htmlObject)
      .data(data).enter()    //And attaching your data.
      .append(//whatever type of graph you want to create)
      ...

})

In the tutorial, there is a part that's the key: 在本教程中,有一部分是关键:

function f(dataset){
    var data = this.cdaResultToD3Array(dataset);
    ...

Apparently, the results from the query specified in your component are passed as the dataset argument to the Custom Chart Script hook on the D3 Component. 显然,组件中指定的查询结果将作为dataset参数传递到D3组件上的“ 自定义图表脚本”钩子。 The call to cdaResultToD3Array is probably specific to the example and will not work, but you will indeed have to manipulate the dataset in some specific way to prepare it for using with your chart code. cdaResultToD3Array的调用可能是特定于该示例的,将无法正常工作,但是您确实必须以某种特定方式操纵数据集,以准备将其与图表代码配合使用。

Then, you can forget about the d3.json('flare.json', function (data) { ... }) part, and use just the code inside that function. 然后,您可以忘记d3.json('flare.json', function (data) { ... })部分,而仅使用该函数中的代码。 Your data will be bound to the elements and the chart will draw. 您的数据将绑定到元素,然后将绘制图表。

The only catch is the data transformation part. 唯一的问题是数据转换部分。 You will need to adapt your dataset to make it work with the circle packing code. 您将需要调整数据集以使其与圆包装代码一起使用。

Tip: make it look exactly like that in flare.json 提示:使其与flare.json外观完全一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM