How to set the size of a chartlabel
1. Create a labelmanager,
2. Create a chartlabel,
3. Get the component and
4. Set the preferredsize;
example:
-----------------------------------------------------------------------------
import java.awt.*;
import javax.swing.*;
import com.klg.jclass.chart.*;
import com.klg.jclass.chart.data.JCEditableDataSource;
import com.klg.jclass.util.swing.JCExitFrame;
public class SimplestChart extends JPanel {
JCChart chart;
JCChartLabelManager cl_man;
JCChartLabel cl;
public double xData[][] = {
{ 1, 2, 3, 4, 5, 6 ,7 ,8 ,9},
};
public double yData[][]= {
{ 1, 3, 2, 5, 4, 6, 8 ,7, 5},
};
public SimplestChart() {
setLayout(new BorderLayout());
setPreferredSize(new Dimension(600, 600));
chart = new JCChart();
ChartDataView arr = chart.getDataView(0);
arr.setDataSource(new JCEditableDataSource( xData, yData, null, null, ""));
chart.getChartArea().getPlotArea().setLeft(25);
chart.getChartArea().getPlotArea().setRight(10);
chart.getChartArea().getPlotArea().setTop(10);
chart.getChartArea().getPlotArea().setBottom(20);
chart.setForeground(Color.blue);
cl_man = chart.getChartLabelManager();
cl = new JCChartLabel("Label attached to data");
cl.setDataIndex(new JCDataIndex(chart.getDataView(0), chart.getDataView(0).getSeries(0), 0, 3));
cl.setAttachMethod(JCChartLabel.ATTACH_DATAINDEX);
cl.getComponent().setBorder(BorderFactory.createLineBorder(Color.black));
cl.setOffset(new Point(-50,-120));
cl.getComponent().setPreferredSize(new Dimension (200,100));
cl_man.addChartLabel(cl);
cl.setConnected(true);
add(chart);
}
public static void main(String args[]) {
JCExitFrame f = new JCExitFrame("JClass Chart Example");
SimplestChart easyChart= new SimplestChart();
f.getContentPane().add(easyChart);
f.pack();
f.setVisible(true);
}
}
----------------------------------------------------------------------------------------------------------
© 2021 Quest Software Inc. ALL RIGHTS RESERVED. Feedback Terms of Use Privacy