我在 RAP 上下文中使用 d3 树形图布局。因此,我的树状图嵌入在视图中,并且应该在最初和调整大小后填充该视图。
我阅读了一些有关动态更新树形图的主题,但我觉得它们都没有准确解决我的问题。
this._treemap = d3.layout.treemap()
.value(function(d){return d._value})
.children(function(d) { return d._items })
.size([800,300])
.padding(4)
.nodes(this);
var cells = selection
.data(this._treemap)
.enter()
.append("svg:g")
.attr("class", "item")
.append("rect")
.attr("x", function(d){return d.x;})
.attr("y", function(d){return d.y;})
.attr("width", function(d){return d.dx;})
.attr("height", function(d){return d.dy;})
.attr("fill", function(d){return d.children ? color(d._text) : color(d.parent._text)})
.attr("stroke", "black")
.attr("stroke-width",1);
Run Code Online (Sandbox Code Playgroud)
树状图初始化时设置固定大小。所有计算值(值,x,y,dx,dy)取决于大小集。我使用这个树形图在 svg 中绘制一些矩形。
我已经有一个更新函数可以识别视图的大小调整,并且有很多示例以某种方式处理更新树形图布局,但我无法将它们放在一起。
_updateLayout: function() {
this._width = this._chart._width;
this._height = this._chart._height;
console.log(this._height);
console.log(this._width);
this._layer = this._chart.getLayer( "layer" );
Run Code Online (Sandbox Code Playgroud)
我想用新的大小和位置值更新矩形,但如何将这些值放入布局中?除了创建新布局之外应该还有另一种选择,对吗?
我是 D3 世界的新手,我构建了我的第一个树形图。
我找不到保留最小节点尺寸(特定宽度和高度)的解决方案。
基本上,如果您查看我的 JSfiddle,您会发现大小为 1 的最小节点无法在内部正确显示其标签,因为框/节点太小,因此文本无法容纳。
{"name": "label5", "size": 1}
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何保留/指定最小节点的大小(宽度和高度),以便某些文本/标签适合吗?
这是我完整的JSFiddle:

在 V4 中,不再使用 d3.layout.treemap。所以我正在尝试使用分层 API 构建一个包含平面对象数组的树状图。我发现使用对象的平面阵列的实现在这里。
这是我目前正在尝试构建树状图的代码。
var treeData = d3.stratify()
.id(function(d) { return d[relationMap.label]; })
.parentId(function(d) { return d[relationMap.series]; })
(chart.children);
// assign the name to each node
treeData.each(function(d) {
d.name = d[relationMap.label];
});
var treemap = d3.treemap()
.size([container.width, container.height]);
treemap(root);
svg.append("g").attr("class", "treemap");
var node = svg.select(".treemap")
.selectAll("g")
.data(root.leaves())
.enter().append('g')
.attr('transform', function (d) {
return 'translate(0,0)';
});
node.append('rect')
// .call(position)
.attr("x", function (d) {
return d.x0 + "px";
})
.attr("y", function (d) {
return d.y0 + "px"; …Run Code Online (Sandbox Code Playgroud) 我是 Shiny 的新手,我正在尝试使用d3TreeR HTML Widget来显示交互式树图
我使用了以下代码,它在 R 中完美运行:
library(readxl)
budget_map <- read_excel(path = 'Trader Dashboard Data Prep Sample.xlsx',sheet='v2',col_names = TRUE)
library(treemap)
budget_treemap <- treemap(budget_map,index=c("Sales Agency","Agency","Advertiser"),vSize="Booked Revenue Net",vColor="Sales Agency",palette = "Set1",type="categorical",title="Australia Budget Map",fontsize.title=22)
library(d3treeR)
d3tree2(budget_treemap)
Run Code Online (Sandbox Code Playgroud)
我试图让它在 Shiny 中渲染并使用以下代码:
library(shiny)
library(readxl)
library(treemap)
library(htmlwidgets)
library(data.tree)
library(d3treeR)
budget_map <- read_excel(path = 'C:/Users/rahul/Desktop/30k foot view/Trader Dashboard Data Prep Sample.xlsx',sheet='v2',col_names = TRUE)
budget_treemap <- treemap(budget_map,index=c("Sales Agency","Agency","Advertiser"),vSize="Booked Revenue Net",vColor="Sales Agency",palette = "Set1",type="categorical")
ui <- fluidPage(
d3tree2Output("au_budget_map")
)
server <- function(input,output){
output$au_budget_map <- renderD3tree2({budget_treemap})
}
shinyApp(ui …Run Code Online (Sandbox Code Playgroud) 我最近从https://www.kaggle.com/philippsp/exploratory-analysis-instacart看到了这张树状图(两级层次结构,彩色,方形树状图)。

它是用 R 制作的,通过:
treemap(tmp,index=c("department","aisle"),vSize="n",title="",
palette="Set3",border.col="#FFFFFF")
Run Code Online (Sandbox Code Playgroud)
我想知道如何在 Python 中制作这个图?
我搜索了一下,但没有找到任何多级树状图示例。
我正在尝试使用 highcharter-package 在 R 中生成交互式树形图(顺便说一句,我喜欢这个包)。它应该看起来像这样(我什至不需要不同的级别)
示例代码:
df <- data.frame(name = c("john", "jane", "herbert", "peter"),
bananas = c(10, 14, 6, 3))
hctreemap2(df,
group_vars = "name",
size_var = "bananas")
Run Code Online (Sandbox Code Playgroud)
我不希望盒子有渐变颜色,而是不同的颜色,比如红色、黄色、绿色和蓝色。我对 highcharts-API 的理解越来越深入,并将其“翻译”为 R 代码,但这确实让我很困难。
我已经找到了解决方法,但我正在寻找更好的解决方案,因为 hc_add_series_treemap 已被弃用。
p <- treemap(df,
index="name",
vSize="bananas",
type="index")
highchart() %>%
hc_add_series_treemap(p,
layoutAlgorithm = "squarified")
Run Code Online (Sandbox Code Playgroud)
所以感谢您的帮助:)
我有一个TreeMap<Date, Integer>,我想从该地图中获取第n个项目。我现在想到的是:
((Integer)myTreeMap.values().toArray()[index]).intValue();
Run Code Online (Sandbox Code Playgroud)
但这感觉很笨重,更不用说堆上或性能上发生了什么?
有没有一种简洁的方法可以从/获取第n项?TreeMapSortedMap
我正在使用plotlyexpress 来制作树形图。我想用标签以及父级的百分比和色阶中使用的值来注释我的数据扇区。
如何添加注释来显示color树形图参数中使用的实际值?在下面的示例代码中,我想为每个部门注释“薪水”。我还想添加一些额外的文字来描述每个部门的数字。例如,“总计百分比:”附加到百分比值以获取更多文本描述将非常适合帮助对树形图进行更多注释。任何添加自定义文本的方法都是有益的。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
d = {'count': [1,1,1,2,2,3,3,3,4],
'name': ['bob','bob','bob','shelby','shelby','jordan','jordan','jordan','jeff'],
'type': ['type1','type2','type4','type1','type6','type5','type8','type2',None],
'salary':[1000,2000,3000,10000,15000,30000,100000,50000,25000]}
df = pd.DataFrame(data=d)
# group data and aggregate
df_plot = df.groupby(['name','type'])[['salary','count']].sum().reset_index()
avg_salary = df_plot['salary'].sum()/df_plot['count'].sum()
# plot treemap
fig = px.treemap(df_plot,
values='count',
color='salary',
color_continuous_scale='balance',
color_continuous_midpoint=avg_salary,
path=['type','name'])
fig.data[0].textinfo = 'label+value+percent parent'
fig.show()
Run Code Online (Sandbox Code Playgroud) 我正在尝试java.util.TreeMap在J2ME应用程序中使用.我知道它TreeMap存在于J2SE上但不存在于J2ME上,所以我已经做了一些努力将J2SE 6.0移植TreeMap到J2ME 1.2并将其包含在我的Midlet Jar中.这涉及移植一半的集合框架,但现在我(理论上)完成了它并想要测试它.
但是当我在SUN J2ME SDK 3.0模拟器(DefauldClclPhone2)上启动我的应用程序时,我得到以下异常:
java.lang.NoClassDefFoundError: java/util/TreeMap
java.lang.Class.invoke_verify(), bci=0
java.lang.Class.initialize(), bci=117
com.companyname.test.TestMidlet.<init>(), bci=19
java.lang.Class.newInstance(), bci=0
com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=46
com.sun.midp.midlet.MIDletStateHandler.createMIDlet(), bci=66
com.sun.midp.midlet.MIDletStateHandler.createAndRegisterMIDlet(), bci=17
com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=27
com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
Run Code Online (Sandbox Code Playgroud)
在我得到的真实设备上"Error in Application"但看不到实际的异常,因为我现在没有匹配的SDK.
我的应用程序成功地经历了预验证过程,我感到很困惑.我总是经历过一个缺失的课程(前几天我有很多课程)在预验证器中触发错误.所以我得出结论,在成功预先验证之后NoClassDefFoundError,设备上就没有任何东西了.
我的jar里面的目录结构如下:
test.jar
com
companyname
(my application classes, including the Midlet class)
java
lang
Comarable.class
Iterable.class
(some others which are missing on J2ME)
util
TreeMap.class
TreeSet.class
(many others which …Run Code Online (Sandbox Code Playgroud) 我有一个很大的列表并将其放入树形图中.
然后我想把"ALL"放在列表的最顶端,但是在"ALL"之前有"AAA"的东西
编辑:我想要对所有其他输入进行排序
List -> List
----- -----
AAA AAA
BBB ALL
CCC BBB
CCC
Run Code Online (Sandbox Code Playgroud)
我可以使用arrayList或其他东西,但我想知道是否有办法控制这种情况.
treemap ×10
d3.js ×3
java ×3
javascript ×3
python ×2
charts ×1
cldc ×1
collections ×1
highcharts ×1
htmlwidgets ×1
java-me ×1
json ×1
matplotlib ×1
midp ×1
pandas ×1
plotly ×1
r ×1
shiny ×1
sortedmap ×1
string ×1