resizing of TChart

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
SDG
Newbie
Newbie
Posts: 40
Joined: Tue Apr 08, 2003 4:00 am

resizing of TChart

Post by SDG » Fri May 29, 2009 1:12 pm

Hello,

I am instantiating "chart1 = new TChart()" in a class "ChartPanel" extended with JPanel. Another class "MyChart" is implemented and extended with ChartPanel. Now "MyChart mychart = new MyChart();" is called in a JFrame class and when I run, my JFrame class shows with maximized size, but the chart doesn't maximize. How do I resize chart. Even "chart1.setSize(1280, 1024);" did not work. The chart displayed center top of the screen, but very small in size.

Thanks in advance.

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 May 29, 2009 2:48 pm

Hi SDG,

In that case you may need to set its layout using GroupLayout with corresponding chart, JPanel, etc. You'll find examples of this in the TeeChart.Features.jar demo project included with TeeChart's installation.

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

SDG
Newbie
Newbie
Posts: 40
Joined: Tue Apr 08, 2003 4:00 am

Post by SDG » Fri May 29, 2009 3:09 pm

Hi Narcís,

I did not find any method "GroupLayout" in the demo source. Eventhough I changed the size of chart1, but visually there is not change in the size. Please give me methods to change the size of the chart.

Below is my code.

Base class:

public class ChartPanel extends JPanel {

protected TChart chart1;
public ChartPanel() {
super();
chart1 = new TChart();
chart1.getFooter().setVisible(false);
chart1.getHeader().setVisible(false);
chart1.getAspect().setView3D(true);
Gradient g=chart1.getPanel().getGradient();
g.setDirection(GradientDirection.VERTICAL);
// Smooth gray-like colors that adapt correctly to all demos:
g.setEndColor(new com.steema.teechart.drawing.Color(109,109,109));
g.setMiddleColor(new com.steema.teechart.drawing.Color(149,202,255));
g.setStartColor(new com.steema.teechart.drawing.Color(0,115,230));
g.setVisible(true);
chart1.getAxes().getLeft().getAxisPen().setWidth(1);
chart1.getAxes().getBottom().getAxisPen().setWidth(1);
chart1.getHeader().getFont().setColor(new com.steema.teechart.drawing.Color(226,226,226));
ColorPalettes.applyPalette(chart1.getChart(),1); // Excel color palette
chart1.setSize(1080, 1024);
//chart1.setLayout(new BorderLayout());
/*chart1.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createBevelBorder(BevelBorder.RAISED),
BorderFactory.createEmptyBorder(2, 2, 2, 2)));*/
System.out.println(chart1.getSize().height);
System.out.println(chart1.getSize().width);
chart1.validate();
chart1.getChart().setWidth(1024);
this.add(chart1, BorderLayout.CENTER);
this.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createBevelBorder(BevelBorder.RAISED),
BorderFactory.createEmptyBorder(2, 2, 2, 2)));
this.setSize(500, 500);
this.validate();
this.repaint();
/*
basePane = new JPanel();
{
basePane.setLayout(new BorderLayout());
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
buttonPane.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createBevelBorder(BevelBorder.RAISED),
BorderFactory.createEmptyBorder(6, 6, 6, 6)));
basePane.add(buttonPane, BorderLayout.PAGE_START);
}
this.add(basePane)
*/
}

}

Implementor class:
public class MyChart extends ChartPanel implements ActionListener {

private JButton editButton;
private JComboBox styleList;
private JButton showEditorButton;

public MyChart() {
//styleList.addActionListener(this);
//editButton.addActionListener(this);
showEditorButton = new JButton("Show the chart editor");
Line series1;
series1 = new Line(chart1.getChart());
series1.fillSampleValues();
series1.setColorEach(false);
series1.getMarks().setArrowLength(20);
series1.getMarks().setVisible(true);

Line series2;
series2 = new Line(chart1.getChart());
series2.fillSampleValues();
series2.setColorEach(true);
series2.getMarks().setArrowLength(20);
series2.getMarks().setVisible(true);

Line series3;
series3 = new Line(chart1.getChart());
series3.fillSampleValues();
series3.setColorEach(true);
series3.getMarks().setArrowLength(20);
series3.getMarks().setVisible(true);

Line series4;
series4 = new Line(chart1.getChart());
series4.fillSampleValues();
series4.setColorEach(true);
series4.getMarks().setArrowLength(20);
series4.getMarks().setVisible(true);

editButton = new JButton("Edit...");
styleList = new JComboBox(
new String[] {
"Rectangle",
"Pyramid",
"Inverted Pyramid",
"Cylinder",
"Ellipse",
"Arrow",
"Rect. Gradient",
"Cone"});
styleList.setSelectedIndex(6);
validate();
repaint();
this.add(showEditorButton, BorderLayout.NORTH);
showEditorButton.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
if (source == showEditorButton) {
ChartEditor.editChart(chart1.getChart(), "myChart...");
}
}
}

Calling class:

public class JFChart extends JFrame {

public JFChart(){
MyChart mychart = new MyChart();
setTitle("Bar Chart Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
setSize(600, 600);
show();
getContentPane().add(mychart,BorderLayout.CENTER);
validate();
repaint();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFChart jfChart = new JFChart();
}

}

I have got completely stuckup in chart resize.

Thanks in advance.

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 May 29, 2009 3:41 pm

Hi SDG,

Could this be because in the calling classe you are setting it to 600x600?

Code: Select all

setSize(600, 600); 
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

SDG
Newbie
Newbie
Posts: 40
Joined: Tue Apr 08, 2003 4:00 am

Post by SDG » Sat May 30, 2009 6:30 am

It is showing much lesser than 600x600. Even I tested with setSize(1080, 1024); in calling class, no change.

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

Post by Narcís » Mon Jun 01, 2009 12:54 pm

Hi SDG,

TChart.java does not currently allow setting of preferredSize, required if you wish to modify defaultsize on a Chart at form load time when using BorderLayout (if not can use tChart1.setSize(600,500);tChart1.refreshControl(); posterior to load). We are enabling write for preferredSize in the next maintenance release. In the meantime it can be manually added to the TChart source by looking for the 'getPreferredSize' method and replacing it with the following code:

TChart.java:

Code: Select all

    private Dimension defaultDimension = new Dimension(400, 250); 

    public Dimension getPreferredSize() { 
        return defaultDimension; 
    } 

    public void setPreferredSize(Dimension dim) { 
        defaultDimension = dim; 
    } 

You can then set PreferredSize in the following way at Chart create time, thus the BorderLayout used by your form will use the size you set. When using GroupLayout the problem doesn't occur as you can set Chart size at form create time.

Modifying preferred Chart size at runtime.:

Code: Select all

        java.awt.Dimension newDim = new java.awt.Dimension(500,600); 
        chart1.setPreferredSize(newDim); 
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

Post Reply