嗨,我想用jchart2d显示水平条形图。问题在于第一个横条正在接触Y轴。我的目标是将第一个垂直条移到Y轴的右侧,但找不到实现方法。
在这里您可以看到问题:
这是代码:
public static void main(String[]args){
// Create a chart:
Chart2D chart = new Chart2D();
// Create an ITrace:
ITrace2D trace = new Trace2DSimple();
// change to vertical bar diagram
TracePainterVerticalBar vb = new TracePainterVerticalBar(chart);
vb.setBarWidth(15);
trace.setTracePainter(vb);
trace.setColor(Color.blue);
// Add the trace to the chart. This has to be done before adding points (deadlock prevention):
chart.addTrace(trace);
chart.getAxisY().setRangePolicy(new RangePolicyFixedViewport(new Range(200, 500)));
chart.getAxisX().setRangePolicy(new RangePolicyFixedViewport(new Range(1, 49)));
//chart.getAxisX().setStartMajorTick(true);
IAxis<IAxisScalePolicy> xAxis = (IAxis<IAxisScalePolicy>)chart.getAxisX();
xAxis.setAxisScalePolicy(new AxisScalePolicyManualTicks());
xAxis.setMajorTickSpacing(1);
xAxis.setMinorTickSpacing(1);
xAxis.setStartMajorTick(true);
// Add all points, as it is static:
for(int i=0;i<StatisticsManager.getInstance().getMostUsedNumers().size();i++){
trace.addPoint((i+1),StatisticsManager.getInstance().getMostUsedNumers().get(i));
}
// Make it visible:
// Create a frame.
JFrame frame = new JFrame("MinimalStaticChart");
// add the chart to the frame:
frame.getContentPane().add(chart);
frame.setSize(400,300);
// Enable the termination button [cross on the upper right edge]:
frame.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
frame.setVisible(true);
}