|
Hidden/Transparent Axis appear with addLineLayer |
Posted by Dave Pick on Feb-29-2012 18:38 |
|
Hi,
I am using Chart Directory java version 5.0.2.
I have hidden the y Axis grid lines by setting the colour to Chart.Transparent, however when I add a LineLayer to the chart the grid lines re-appear.
Do I need to do anything else to the chart and/or line layer?
Many Thanks
Dave
Here is a simple example to recreate the problem:
package test;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import ChartDirector.Axis;
import ChartDirector.Chart;
import ChartDirector.ChartViewer;
import ChartDirector.XYChart;
public class ChartDirectorTest {
public static void main(String[] args) {
ChartDirectorTest test = new ChartDirectorTest();
JFrame frame = new JFrame(test.toString());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.getContentPane().setBackground(Color.white);
ChartViewer viewer = new ChartViewer();
test.createChart(viewer, 0);
frame.getContentPane().add(viewer);
frame.pack();
frame.setVisible(true);
}
public void createChart(ChartViewer viewer, int index) {
final XYChart chart = new XYChart(500, 400);
final double data[]= { 19026.5, 19803.5, 19688.5, 20491.5, 20320.5 };
final String[] labels = { "8", "9", "10", "11", "12" };
chart.setPlotArea(50, 58, 350, 250, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
chart.setYAxisOnRight(true);
final Axis yAxis = chart.yAxis();
yAxis.setColors(Chart.Transparent);
yAxis.setAutoScale(0);
yAxis.setTickColor(Chart.Transparent);
final Axis yAxis2 = chart.yAxis2();
yAxis2.setColors(Chart.Transparent);
yAxis2.setTickColor(Chart.Transparent);
final Axis xAxis = chart.xAxis();
xAxis.setLabels(labels);
xAxis.setTickColor(Chart.Transparent);
// THIS CAUSES THE Y-AXIS GRID LINES TO APPEAR
chart.addLineLayer(data, 0x8787C9);
viewer.setImage(chart.makeImage());
}
} |
Re: Hidden/Transparent Axis appear with addLineLayer |
Posted by Peter Kwan on Feb-29-2012 21:56 |
|
Hi Dave,
The Axis.setColors and Axis.setTickColors only sets the color of the axis stem, labels, title and ticks. (A "tick" is a small line, typically a few pixels long, that joins the label to the axis stem.) In your case, the grid lines are in fact set to light grey 0xcccccc in XYChart.setPlotArea line. If your chart has no data, the axis has no scale and the grid line may not appear. If there are data, the axis will auto-scale and the grid lines will appear.
To solve the problem, please set the grid color to Chart.Transparent in XYChart.setPlotArea.
chart.setPlotArea(50, 58, 350, 250, 0xffffff, -1, -1, Chart.Transparent, Chart.Transparent);
Hope this can help.
Regards
Peter Kwan |
Re: Hidden/Transparent Axis appear with addLineLayer |
Posted by Dave Pick on Feb-29-2012 22:06 |
|
Hi
That has solved the problem.
Many thanks. |
|