Histogram

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Jesse
Newbie
Newbie
Posts: 28
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin, TX

Histogram

Post by Jesse » Thu Mar 19, 2009 10:07 pm

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);

		}
}

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Mar 20, 2009 3:26 pm

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!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Jesse
Newbie
Newbie
Posts: 28
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin, TX

Post by Jesse » Fri Mar 20, 2009 4:36 pm

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.

Post Reply