Plot2DPanel-设置轴字符串标签

时间:2013-11-05 09:36:32

标签: java groovy plot javaplot

我正在尝试但没有成功通过Plot2DPanel显示屏上的字符串标签替换数字标签。

以下是使用数字X轴标签的图表外观:

plot in a JFrame

以下是我使用的代码:

    // create your PlotPanel (you can use it as a JPanel)
    Plot2DPanel plot = new Plot2DPanel();

    // add the histogram (50 slices) of x to the PlotPanel
    plot.addHistogramPlot("my plot", x);

    // put the PlotPanel in a JFrame like a JPanel
    JFrame frame = new JFrame("a plot panel");
    frame.setSize(600, 600);
    frame.setContentPane(plot);
    frame.setVisible(true); 

我尝试在frame.setContentPane(plot);之前添加此行来更改轴标签:

    plot.getAxis(0).setStringMap(legend);

如果图例是HashMap<String, Double>,则将字符串标签映射到轴上的位置,但这不会改变图中的任何内容。

我无法想象我在这里缺少什么。任何建议都将不胜感激!

谢谢!

kevinad

注意:如果有任何兴趣,我会通过X11转发从gromy输出gremlin shell。

1 个答案:

答案 0 :(得分:0)

要设置图例,必须使用:

plot.setAxisLabels("Legend Y", "Legend X");

希望这会有所帮助: - )