次のようなプリフューズを使用して積み上げ面グラフを作成したいと思います:http: //prefuse.org/gallery/namevoyager/
ただし、どこから始めればよいのかよくわかりません。また、これらのグラフのサンプルコードはありません。prefuse.action.layout.StackedAreaChartを見つけましたが、どうしたらよいかわかりません。
次のようなプリフューズを使用して積み上げ面グラフを作成したいと思います:http: //prefuse.org/gallery/namevoyager/
ただし、どこから始めればよいのかよくわかりません。また、これらのグラフのサンプルコードはありません。prefuse.action.layout.StackedAreaChartを見つけましたが、どうしたらよいかわかりません。
StackedAreaChartレイアウトを使用するためのコンパイル可能な例を次に示します。他のどこにも見つからなかったので、他の人の参考になることを願って、ここに含めています。ここで重要なのは、StackedAreaChartがテーブルが次のスキーマに従っていることを前提としていることを理解することです。
ここにあります:
import javax.swing.JFrame;
import prefuse.Constants;
import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.ActionList;
import prefuse.action.RepaintAction;
import prefuse.action.assignment.ColorAction;
import prefuse.action.assignment.DataColorAction;
import prefuse.action.layout.StackedAreaChart;
import prefuse.data.Table;
import prefuse.render.DefaultRendererFactory;
import prefuse.render.PolygonRenderer;
import prefuse.util.ColorLib;
import prefuse.visual.VisualItem;
class Main {
public static void main(String[] args) {
ActionList color = new ActionList();
int[] palette = new int[] {
ColorLib.rgba(255,200,200,150),
ColorLib.rgba(200,255,200,150)
};
ColorAction fillColor = new DataColorAction("table", "name",
Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
color.add(fillColor);
ActionList layout = new ActionList();
layout.add(new RepaintAction());
String[] fields = { "1980s", "1990s", "2000s" };
layout.add(new StackedAreaChart("table", VisualItem.POLYGON, fields));
Visualization vis = new Visualization();
Table table = new Table();
vis.add("table", table);
table.addColumn("name", String.class);
table.addColumn("1980s", int.class);
table.addColumn("1990s", int.class);
table.addColumn("2000s", int.class);
table.addColumn(VisualItem.POLYGON, float[].class, null);
table.addColumn(VisualItem.POLYGON+":start", float[].class, null);
table.addColumn(VisualItem.POLYGON+":end", float[].class, null);
int rowNumber = table.addRow();
table.setString(rowNumber, "name", "Bob");
table.setInt(rowNumber, "1980s", 1000);
table.setInt(rowNumber, "1990s", 500);
table.setInt(rowNumber, "2000s", 300);
rowNumber = table.addRow();
table.setString(rowNumber, "name", "Mary");
table.setInt(rowNumber, "1980s", 800);
table.setInt(rowNumber, "1990s", 1500);
table.setInt(rowNumber, "2000s", 3200);
vis.putAction("layout", layout);
vis.putAction("color", color);
DefaultRendererFactory drf = new DefaultRendererFactory();
drf.add("ingroup('table')", new PolygonRenderer());
vis.setRendererFactory(drf);
Display display = new Display(vis);
display.setSize(720, 500);
JFrame frame = new JFrame("Prefuse StackedAreaChart Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(display);
frame.pack();
frame.setVisible(true);
vis.run("layout");
vis.run("color");
}
}
軸を表示するには、prefuseディストリビューションに含まれているCongress.javaデモを参照してください。
Prefuseのマニュアルを確認しましたか?(完全ではありませんが、そもそも何かです)。
その中には、グラフ要素にデータをロードする方法と、それを視覚化アイテムにデプロイする方法を示すサンプルアプリケーションがあります。
を生成するStackedAreaChart
には、データをオブジェクトにロードする必要があります。このprefuse.data.Table
オブジェクトは、例として、CSVファイルからロードできます。
CSVTableReader reader=new CSVTableReader();
Table myTable=reader.readTable("/myDataFile.csv");
次に、テーブルをデータグループ、つまり「テーブル」としてビジュアライゼーションに追加します。
Visualization vis = new Visualization();
vis.add("table", myTable);
次に、StackedAreaChartを作成し、それを視覚化アクションコレクションに追加します。
//params: name of the data group to layout, name of the data field in which to store computed polygons, and an array containing the names of the various data fields, in sorted order, that should be referenced for each consecutive point of a stack layer
StackedAreaChart chart=new StackedAreaChart ("table", fieldName, csvColumnsToCompute);
//add the layout action with a unique key
vis.putAction("myChartLayout", chart);
次に、さまざまなレイアウトアクション、またはその他の視覚的側面を構成できます(リンクされた例を参照)。
最後に、グラフを表示するには、Displayオブジェクトを作成し、ビジュアライゼーションをバインドして、その上でレイアウトアクションを実行する必要があります。
//this Display initialization is extracted from the Example app
Display d = new Display(vis);
d.setSize(720, 500); // set display size
// drag individual items around
d.addControlListener(new DragControl());
// pan with left-click drag on background
d.addControlListener(new PanControl());
// zoom with right-click drag
d.addControlListener(new ZoomControl());
// create a new window to hold the visualization
JFrame frame = new JFrame("prefuse example");
// ensure application exits when window is closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(d);
frame.pack(); // layout components in window
frame.setVisible(true); // show the window
//At the end: RUN THE CHART ACTION:
vis.run("myChartLayout");
これが少なくとも最初の開始として役立つことを願っています(コードスニペットはコピーアンドペーストを目的としておらず、コンパイルエラーが含まれている可能性があります)。
幸運を。