x legend with ticks every 5
This commit is contained in:
parent
2830447bae
commit
05d3fe3861
@ -50,7 +50,9 @@ public class XLegendPainter extends OHLCChartPainter {
|
||||
public void drawChart(Graphics2D g, ChartPanel p, ChartDef def) {
|
||||
|
||||
init(g);
|
||||
int big_tick = 10;
|
||||
int caption_tick = 10;
|
||||
int long_tick = 5;
|
||||
|
||||
Dimension size = p.getSize();
|
||||
|
||||
int first_bar = getFirstBar(p);
|
||||
@ -59,28 +61,29 @@ public class XLegendPainter extends OHLCChartPainter {
|
||||
String text = getTimeStrAt(data, first_bar);
|
||||
int swidth = g.getFontMetrics().stringWidth(text);
|
||||
|
||||
big_tick = swidth * 2 / ((int) ticksize);
|
||||
big_tick = (big_tick / 5) * 5 + 5;
|
||||
caption_tick = swidth * 2 / ((int) ticksize);
|
||||
caption_tick = (caption_tick / 5) * 5 + 5;
|
||||
|
||||
int n;
|
||||
int x;
|
||||
double x;
|
||||
int y = 0;
|
||||
|
||||
for (n = first_bar, x = 0; x < size.width; x += ticksize) {
|
||||
|
||||
if (n % big_tick == 0) {
|
||||
|
||||
if (n % long_tick == 0) {
|
||||
g.drawLine((int) x, y, (int) x, y + em_size);
|
||||
} else {
|
||||
g.drawLine((int) x, y, (int) x, y + em_size / 2);
|
||||
}
|
||||
|
||||
if (n % caption_tick == 0) {
|
||||
|
||||
text = getTimeStrAt(data, n);
|
||||
|
||||
swidth = g.getFontMetrics().stringWidth(text);
|
||||
g.drawString(text, (int) x - swidth / 2, y + em_size * 3);
|
||||
|
||||
} else {
|
||||
g.drawLine((int) x, y, (int) x, y + em_size / 2);
|
||||
}
|
||||
|
||||
n += 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user