public class FirstPanel extends JFrame implements ActionListener{
class Measure extends JPanel
{
ArrayList<String> edgearry =new ArrayList<String>();
ArrayList<String> datavaluelist =new ArrayList<String>();
//edgearry.add("data1");
//edgearry.add("data2");
//edgearry.add("data3");
//....
//.....
//edgearry.add("data100");
condition con2=new condition();
public Measure()
{
JComponent jcgraph=creategraphpanel();
TitledBorder tgraph=new TitledBorder("Graph");
setBorder(tgraph);
setLayout(new GridLayout(0,1));
add(jcgraph);
}
public JComponent creategraphpanel()
{
JPanel graphpanel=new JPanel(); graphpanel.add(getChart2DDemoE());
JScrollPane scroller = new JScrollPane(graphpanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
return scroller;
}
private Chart2D getChart2DDemoE() {
//<-- Begin Chart2D configuration -->
//edgearry is an arraylist of label(which i dynamically get from my application)
String labelsAxisLabels[]=(String[]) edgearry.toArray(new String[edgearry.size()]);
//Configure object properties
Object2DProperties object2DProps = new Object2DProperties();
object2DProps.setObjectTitleText ("Heading");
//Configure chart properties
Chart2DProperties chart2DProps = new Chart2DProperties();
chart2DProps.setChartDataLabelsPrecision (2);
//Configure legend properties
LegendProperties legendProps = new LegendProperties();
String[] legendLabels = {"label1", "label2", "label3","label4","label5"};
legendProps.setLegendLabelsTexts (legendLabels);
//Configure graph chart properties
GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties();
graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels);
graphChart2DProps.setLabelsAxisTitleText ("Heading");
graphChart2DProps.setNumbersAxisTitleText ("Heading");
graphChart2DProps.setChartDatasetCustomizeGreatestValue (true);
graphChart2DProps.setChartDatasetCustomGreatestValue (48f);
graphChart2DProps.setChartDatasetCustomizeLeastValue (true);
graphChart2DProps.setChartDatasetCustomLeastValue (0f);
//Configure graph properties
GraphProperties graphProps = new GraphProperties();
graphProps.setGraphAllowComponentAlignment (true);
graphProps.setGraphBarsRoundingRatio (0f);
graphProps.setGraphOutlineComponentsExistence (true);
//Configure dataset
Dataset dataset = new Dataset (5,edgearry.size(), 1);
int setcount=0;
datavaluelist.add("value1;value2;value3;");
datavaluelist.add("value1;");
datavaluelist.add("value2;value5");
datavaluelist.add("value3;value4");
for(String al:datavaluelist)
{
String alarray[]=al.split(";");
int firstCount=0;
int secondCount=0;
int thirdCount=0;
int fourthCount=0;
int fifthCount=0;
for(int count=0;count<alarray.length;count++)
{
if(alarray[count].equalsIgnoreCase("value1"))
{
firstCount++;
}
else if(alarray[count].equalsIgnoreCase("value2"))
{
secondCount++;
}
else if(alarray[count].equalsIgnoreCase("value3"))
{
thirdCount++;
}
else if(alarray[count].equalsIgnoreCase("value4"))
{
fourthCount++;
}
else if(alarray[count].equalsIgnoreCase("value5"))
{
fifthCount++;
}
}
dataset.set(0,setcount,0,firstCount*1f);
dataset.set(1,setcount,0,secondCount*1f);
dataset.set(2,setcount,0,thirdCount*1f);
dataset.set(3,setcount,0,fourthCount*1f);
dataset.set(4,setcount,0,fifthCount*1f);
setcount++;
}
dataset.doConvertToStacked();
//Configure graph component colors
MultiColorsProperties multiColorsProps = new MultiColorsProperties();
//Configure chart
LLChart2D chart2D = new LLChart2D();
chart2D.setObject2DProperties (object2DProps);
chart2D.setChart2DProperties (chart2DProps);
chart2D.setLegendProperties (legendProps);
chart2D.setGraphChart2DProperties (graphChart2DProps);
chart2D.addGraphProperties (graphProps);
chart2D.addDataset (dataset);
chart2D.addMultiColorsProperties (multiColorsProps);
//Optional validation: Prints debug messages if invalid only.
if (!chart2D.validate (false)) chart2D.validate (true);
//<-- End Chart2D configuration -->
return chart2D;
}
public void actionPerformed(ActionEvent e) {
Measure ass=new Measure();
JFrame frame = new JFrame("Graph Heading");
frame.getContentPane().add(ass);
frame.pack();
frame.setVisible(true);
}
} |