Page 1 of 1

Histogram

Posted: Thu Mar 19, 2009 10:07 pm
by 7667592
When I create a histogram, the axis is set to the bottom of the smallest bar by default. This makes one of the bins look like it has a zero count. What am I doing wrong?

Code: Select all

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.steema.teechart.TChart;
import com.steema.teechart.styles.Histogram;

public class ChartTest {

	public static void main(String[] args) {
			JFrame frame = new JFrame();
			ChartTest c = new ChartTest();
			JPanel panel = new JPanel();
			TChart chart = new TChart();
			panel.add(chart);
			frame.add(panel);
			Histogram h = new Histogram();
			h.add(1,10);
			h.add(2,20);
			h.add(3,5);
			h.add(4,25);
			h.add(5,15);
			h.setChart(chart.getChart());
			chart.getAspect().setView3D(false);
			chart.getAspect().setSmoothingMode(false);
			frame.pack();
			frame.setVisible(true);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		}
}

Posted: Fri Mar 20, 2009 3:26 pm
by narcis
Hi Jesse,

In that case you can set left axis minimum value like this:

Code: Select all

         chart.getAxes().getLeft().setAutomaticMinimum(false);
         chart.getAxes().getLeft().setMinimum(0);
Hope this helps!

Posted: Fri Mar 20, 2009 4:36 pm
by 7667592
Excellent. That appears to solve my problem very well.

I had also tried the following, that seemed to do similar.

Code: Select all

		double max = teeChart.getChart().getMaxYValue(teeChart.getAxes().getLeft());
		teeChart.getAxes().getLeft().setMinMax(0.0,max);
I like your solution better. Thank you.