如何使用 Prefuse 创建聚类条形图?
我能够使用 Samir Talwar 的代码通过修改渲染器来创建单个条形图,如下所示:
vis.setRendererFactory(new RendererFactory() {
Renderer yAxisRenderer = new AxisRenderer(Constants.RIGHT, Constants.TOP);
Renderer xAxisRenderer = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);
Renderer barRenderer = new ShapeRenderer() {
protected Shape getRawShape(VisualItem item) {
double x = item.getX();
double y = item.getY();
if (Double.isNaN(x) || Double.isInfinite(x))
x = getInsets().left + axisWidth + totalBarWidth / 2;
if (Double.isNaN(y) || Double.isInfinite(y))
y = 0;
double width = totalBarWidth / (barCount + 1) - barGap;
double height = getHeight() - getInsets().bottom - axisHeight - y;
x -= width / 2;
item.setFillColor(item.getStrokeColor());
return rectangle(x, y, width, height);
}
};
public Renderer getRenderer(VisualItem item) {
return item.isInGroup("ylab") ? yAxisRenderer :
item.isInGroup("xlab") ? xAxisRenderer :
barRenderer;
}
无论如何,我尝试着寻找创建集群条形图的可能性,其中单个值有多个条形图,但遇到困难。另外,我不使用JFreechart的原因是因为我需要prefuse的过滤和搜索功能,这些功能在我的研究中的分析方面证明非常有用。
I was able to create a single bar graph using the code from Samir Talwar by modifying the renderer as the following:
vis.setRendererFactory(new RendererFactory() {
Renderer yAxisRenderer = new AxisRenderer(Constants.RIGHT, Constants.TOP);
Renderer xAxisRenderer = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);
Renderer barRenderer = new ShapeRenderer() {
protected Shape getRawShape(VisualItem item) {
double x = item.getX();
double y = item.getY();
if (Double.isNaN(x) || Double.isInfinite(x))
x = getInsets().left + axisWidth + totalBarWidth / 2;
if (Double.isNaN(y) || Double.isInfinite(y))
y = 0;
double width = totalBarWidth / (barCount + 1) - barGap;
double height = getHeight() - getInsets().bottom - axisHeight - y;
x -= width / 2;
item.setFillColor(item.getStrokeColor());
return rectangle(x, y, width, height);
}
};
public Renderer getRenderer(VisualItem item) {
return item.isInGroup("ylab") ? yAxisRenderer :
item.isInGroup("xlab") ? xAxisRenderer :
barRenderer;
}
Anyhow, I have tried look on the possibility on creating clustered bar graphs where there are multiple bar for a single value but having difficulties. Also, the reason why I do not use JFreechart is because I need prefuse's filtering and searching functions which prove to be very useful in terms of analysis in my research.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论