1 22 23 24 import net.sourceforge.chart2d.*; 25 26 import java.awt.Dimension ; 27 import java.awt.Toolkit ; 28 import java.awt.event.WindowAdapter ; 29 import java.awt.event.WindowEvent ; 30 import javax.swing.JApplet ; 31 import javax.swing.JFrame ; 32 import javax.swing.JTabbedPane ; 33 import java.awt.Color ; 34 import java.util.Random ; 35 36 37 42 public class LBChart2DFrameDemo extends JApplet { 43 44 45 private JFrame frame = null; 46 private static boolean isApplet = true; 47 48 49 54 public static void main (String [] args) { 55 56 isApplet = false; 57 LBChart2DFrameDemo demo = new LBChart2DFrameDemo(); 58 demo.init(); 59 demo.start(); 60 } 62 63 64 67 public void init() { 68 69 JTabbedPane panes = new JTabbedPane (); 71 72 panes.addTab ("Bar", getChart2DDemoA()); 73 panes.addTab ("Bar with Regions", getChart2DDemoB()); 74 panes.addTab ("Bar with Trend Line", getChart2DDemoC()); 75 panes.addTab ("Bar with Cat Coloring", getChart2DDemoD()); 76 panes.addTab ("Bar True Stacked", getChart2DDemoE()); 77 panes.addTab ("Line", getChart2DDemoF()); 78 panes.addTab ("Line with Regions", getChart2DDemoG()); 79 panes.addTab ("Filled Line True Stacked", getChart2DDemoH()); 80 panes.addTab ("Line with Large Dataset", getChart2DDemoI()); 81 panes.addTab ("Scatter / Dot", getChart2DDemoJ()); 82 panes.addTab ("Line and Dot", getChart2DDemoK()); 83 panes.addTab ("Standard Overlay", getChart2DDemoL()); 84 85 boolean dynamicSizeCalc = false; 101 if (dynamicSizeCalc) { 102 int maxWidth = 0; 103 int maxHeight = 0; 104 for (int i = 0; i < panes.getTabCount(); ++i) { 105 Chart2D chart2D = (Chart2D)panes.getComponentAt (i); 106 chart2D.pack(); 107 Dimension size = chart2D.getSize(); 108 maxWidth = maxWidth > size.width ? maxWidth : size.width; 109 maxHeight = maxHeight > size.height ? maxHeight : size.height; 110 } 111 Dimension maxSize = new Dimension (maxWidth, maxHeight); 112 System.out.println (maxSize); 113 for (int i = 0; i < panes.getTabCount(); ++i) { 114 Chart2D chart2D = (Chart2D)panes.getComponentAt (i); 115 chart2D.setSize (maxSize); 116 chart2D.setPreferredSize (maxSize); 117 } 118 System.out.println (panes.getPreferredSize()); 119 } 120 else { 121 Dimension maxSize = new Dimension (561, 214); 122 for (int i = 0; i < panes.getTabCount(); ++i) { 123 Chart2D chart2D = (Chart2D)panes.getComponentAt (i); 124 chart2D.setSize (maxSize); 125 chart2D.setPreferredSize (maxSize); 126 } 127 panes.setPreferredSize (new Dimension (566 + 5, 280 + 5)); } 129 130 frame = new JFrame (); 131 frame.getContentPane().add (panes); 132 frame.setTitle ("LBChart2DFrameDemo"); 133 frame.addWindowListener ( 134 new WindowAdapter () { 135 public void windowClosing (WindowEvent e) { 136 destroy(); 137 } } ); 138 frame.pack(); 139 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 140 frame.setLocation ( 141 (screenSize.width - frame.getSize().width) / 2, 142 (screenSize.height - frame.getSize().height) / 2); 143 } 144 145 146 149 public void start() { 150 frame.show(); 151 } 152 153 154 157 public void destroy() { 158 159 if (frame != null) frame.dispose(); 160 if (!isApplet) System.exit (0); 161 } 162 163 164 168 private Chart2D getChart2DDemoA() { 169 170 172 Object2DProperties object2DProps = new Object2DProperties(); 174 object2DProps.setObjectTitleText ("Amperage Used Per Appliance"); 175 176 Chart2DProperties chart2DProps = new Chart2DProperties(); 178 chart2DProps.setChartDataLabelsPrecision (-1); 179 180 LegendProperties legendProps = new LegendProperties(); 182 String [] legendLabels = {"2002", "2001", "2000"}; 183 legendProps.setLegendLabelsTexts (legendLabels); 184 185 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 187 String [] labelsAxisLabels = {"Computer", "Monitor", "AC", "Lighting", "Refrigerator"}; 188 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 189 graphChart2DProps.setLabelsAxisTitleText ("Appliances"); 190 graphChart2DProps.setNumbersAxisTitleText ("Amps on 120 Volt Line"); 191 192 GraphProperties graphProps = new GraphProperties(); 194 195 Dataset dataset = new Dataset (3, 5, 1); 197 dataset.set (0, 0, 0, 3.5f); 198 dataset.set (0, 1, 0, 2.5f); 199 dataset.set (0, 2, 0, 10.0f); 200 dataset.set (0, 3, 0, 0.5f); 201 dataset.set (0, 4, 0, 2.0f); 202 dataset.set (1, 0, 0, 3.0f); 203 dataset.set (1, 1, 0, 2.0f); 204 dataset.set (1, 2, 0, 10.0f); 205 dataset.set (1, 3, 0, 1.0f); 206 dataset.set (1, 4, 0, 2.0f); 207 dataset.set (2, 0, 0, 2.5f); 208 dataset.set (2, 1, 0, 2.0f); 209 dataset.set (2, 2, 0, 10.5f); 210 dataset.set (2, 3, 0, 1.0f); 211 dataset.set (2, 4, 0, 2.5f); 212 213 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 215 216 LBChart2D chart2D = new LBChart2D(); 218 chart2D.setObject2DProperties (object2DProps); 219 chart2D.setChart2DProperties (chart2DProps); 220 chart2D.setLegendProperties (legendProps); 221 chart2D.setGraphChart2DProperties (graphChart2DProps); 222 chart2D.addGraphProperties (graphProps); 223 chart2D.addDataset (dataset); 224 chart2D.addMultiColorsProperties (multiColorsProps); 225 226 if (!chart2D.validate (false)) chart2D.validate (true); 228 229 231 return chart2D; 232 } 233 234 235 239 private Chart2D getChart2DDemoB() { 240 241 243 Object2DProperties object2DProps = new Object2DProperties(); 245 object2DProps.setObjectTitleText ("Amperage Used Per Appliance"); 246 247 Chart2DProperties chart2DProps = new Chart2DProperties(); 249 chart2DProps.setChartDataLabelsPrecision (-1); 250 251 LegendProperties legendProps = new LegendProperties(); 253 String [] legendLabels = {"2002", "2001", "2000"}; 254 legendProps.setLegendLabelsTexts (legendLabels); 255 256 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 258 String [] labelsAxisLabels = {"Computer", "Monitor", "AC", "Lighting", "Refrigerator"}; 259 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 260 graphChart2DProps.setLabelsAxisTitleText ("Appliances"); 261 graphChart2DProps.setNumbersAxisTitleText ("Amps on 120 Volt Line"); 262 263 GraphProperties graphProps = new GraphProperties(); 265 graphProps.setGraphOutlineComponentsExistence (true); 266 267 Dataset dataset = new Dataset (3, 5, 1); 269 dataset.set (0, 0, 0, 3.5f); 270 dataset.set (0, 1, 0, 2.5f); 271 dataset.set (0, 2, 0, 10.0f); 272 dataset.set (0, 3, 0, 0.5f); 273 dataset.set (0, 4, 0, 2.0f); 274 dataset.set (1, 0, 0, 3.0f); 275 dataset.set (1, 1, 0, 2.0f); 276 dataset.set (1, 2, 0, 10.0f); 277 dataset.set (1, 3, 0, 1.0f); 278 dataset.set (1, 4, 0, 2.0f); 279 dataset.set (2, 0, 0, 2.5f); 280 dataset.set (2, 1, 0, 2.0f); 281 dataset.set (2, 2, 0, 10.5f); 282 dataset.set (2, 3, 0, 1.0f); 283 dataset.set (2, 4, 0, 2.5f); 284 285 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 287 288 WarningRegionProperties warningRegionProps1 = new WarningRegionProperties(); 290 warningRegionProps1.setHigh (WarningRegionProperties.HIGH); 291 warningRegionProps1.setLow (7f); 292 293 WarningRegionProperties warningRegionProps2 = new WarningRegionProperties(); 295 warningRegionProps2.setHigh (7f); 296 warningRegionProps2.setLow (5f); 297 warningRegionProps2.setComponentColor (new Color (146, 105, 0)); 298 warningRegionProps2.setBackgroundColor (new Color (222, 209, 176)); 299 300 LBChart2D chart2D = new LBChart2D(); 302 chart2D.setObject2DProperties (object2DProps); 303 chart2D.setChart2DProperties (chart2DProps); 304 chart2D.setLegendProperties (legendProps); 305 chart2D.setGraphChart2DProperties (graphChart2DProps); 306 chart2D.addGraphProperties (graphProps); 307 chart2D.addDataset (dataset); 308 chart2D.addMultiColorsProperties (multiColorsProps); 309 chart2D.addWarningRegionProperties (warningRegionProps1); 310 chart2D.addWarningRegionProperties (warningRegionProps2); 311 312 if (!chart2D.validate (false)) chart2D.validate (true); 314 315 317 return chart2D; 318 } 319 320 321 325 private Chart2D getChart2DDemoC() { 326 327 329 Object2DProperties object2DProps = new Object2DProperties(); 331 object2DProps.setObjectTitleText ("Productivity by Age"); 332 333 Chart2DProperties chart2DProps = new Chart2DProperties(); 335 chart2DProps.setChartDataLabelsPrecision (-2); 336 337 LegendProperties legendProps = new LegendProperties(); 339 String [] legendLabels = {"Mov. Avg.", "Raw Data"}; 340 legendProps.setLegendLabelsTexts (legendLabels); 341 342 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 344 String [] labelsAxisLabels = 345 {"20-25", "25-30", "30-35", "35-40", "40-45", "45-50", "50-55", "55-60", "60-65"}; 346 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 347 graphChart2DProps.setLabelsAxisTitleText ("Age Ranges"); 348 graphChart2DProps.setNumbersAxisTitleText ("Actual / Optimal"); 349 graphChart2DProps.setChartDatasetCustomizeGreatestValue (true); 350 graphChart2DProps.setChartDatasetCustomGreatestValue (1f); 351 graphChart2DProps.setChartDatasetCustomizeLeastValue (true); 352 graphChart2DProps.setChartDatasetCustomLeastValue (.5f); 353 354 GraphProperties graphProps = new GraphProperties(); 356 graphProps.setGraphComponentsAlphaComposite (graphProps.ALPHA_COMPOSITE_MILD); 357 358 Dataset dataset = new Dataset (1, 9, 1); 360 dataset.set (0, 0, 0, .6f); 361 dataset.set (0, 1, 0, .9f); 362 dataset.set (0, 2, 0, .85f); 363 dataset.set (0, 3, 0, .8f); 364 dataset.set (0, 4, 0, .85f); 365 dataset.set (0, 5, 0, .8f); 366 dataset.set (0, 6, 0, .75f); 367 dataset.set (0, 7, 0, .75f); 368 dataset.set (0, 8, 0, .70f); 369 370 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 372 373 GraphProperties graphPropsTrend = new GraphProperties(); 375 graphPropsTrend.setGraphBarsExistence (false); 376 graphPropsTrend.setGraphLinesExistence (true); 377 378 Dataset datasetTrend = new Dataset(); 380 datasetTrend.addMovingAverage (dataset, 3); 381 382 MultiColorsProperties multiColorsPropsTrend = new MultiColorsProperties(); 384 multiColorsPropsTrend.setColorsCustomize (true); 385 multiColorsPropsTrend.setColorsCustom (new Color [] {new Color (193, 183, 0)}); 386 387 LBChart2D chart2D = new LBChart2D(); 389 chart2D.setObject2DProperties (object2DProps); 390 chart2D.setChart2DProperties (chart2DProps); 391 chart2D.setLegendProperties (legendProps); 392 chart2D.setGraphChart2DProperties (graphChart2DProps); 393 chart2D.addGraphProperties (graphPropsTrend); 394 chart2D.addDataset (datasetTrend); 395 chart2D.addMultiColorsProperties (multiColorsPropsTrend); 396 chart2D.addGraphProperties (graphProps); 397 chart2D.addDataset (dataset); 398 chart2D.addMultiColorsProperties (multiColorsProps); 399 400 if (!chart2D.validate (false)) chart2D.validate (true); 402 403 405 return chart2D; 406 } 407 408 409 413 private Chart2D getChart2DDemoD() { 414 415 417 Object2DProperties object2DProps = new Object2DProperties(); 419 object2DProps.setObjectTitleText ("Productivity by Age"); 420 421 Chart2DProperties chart2DProps = new Chart2DProperties(); 423 chart2DProps.setChartDataLabelsPrecision (-2); 424 425 LegendProperties legendProps = new LegendProperties(); 427 legendProps.setLegendExistence (false); 428 429 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 431 String [] labelsAxisLabels = 432 {"20-25", "25-30", "30-35", "35-40", "40-45", "45-50", "50-55", "55-60", "60-65"}; 433 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 434 graphChart2DProps.setLabelsAxisTitleText ("Age Ranges"); 435 graphChart2DProps.setNumbersAxisTitleText ("Actual / Optimal"); 436 graphChart2DProps.setChartDatasetCustomizeGreatestValue (true); 437 graphChart2DProps.setChartDatasetCustomGreatestValue (1f); 438 graphChart2DProps.setChartDatasetCustomizeLeastValue (true); 439 graphChart2DProps.setChartDatasetCustomLeastValue (.5f); 440 graphChart2DProps.setGraphComponentsColoringByCat (true); 441 graphChart2DProps.setGraphComponentsColorsByCat (new MultiColorsProperties()); 442 443 GraphProperties graphProps = new GraphProperties(); 445 446 Dataset dataset = new Dataset (1, 9, 1); 448 dataset.set (0, 0, 0, .6f); 449 dataset.set (0, 1, 0, .9f); 450 dataset.set (0, 2, 0, .85f); 451 dataset.set (0, 3, 0, .8f); 452 dataset.set (0, 4, 0, .85f); 453 dataset.set (0, 5, 0, .8f); 454 dataset.set (0, 6, 0, .75f); 455 dataset.set (0, 7, 0, .75f); 456 dataset.set (0, 8, 0, .70f); 457 458 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 460 461 LBChart2D chart2D = new LBChart2D(); 463 chart2D.setObject2DProperties (object2DProps); 464 chart2D.setChart2DProperties (chart2DProps); 465 chart2D.setLegendProperties (legendProps); 466 chart2D.setGraphChart2DProperties (graphChart2DProps); 467 chart2D.addGraphProperties (graphProps); 468 chart2D.addDataset (dataset); 469 chart2D.addMultiColorsProperties (multiColorsProps); 470 471 if (!chart2D.validate (false)) chart2D.validate (true); 473 474 476 return chart2D; 477 } 478 479 480 484 private Chart2D getChart2DDemoE() { 485 486 488 Object2DProperties object2DProps = new Object2DProperties(); 490 object2DProps.setObjectTitleText ("Bugs Per MS Product"); 491 492 Chart2DProperties chart2DProps = new Chart2DProperties(); 494 chart2DProps.setChartDataLabelsPrecision (2); 495 496 LegendProperties legendProps = new LegendProperties(); 498 String [] legendLabels = {"Unfound", "Fixed", "Unfixed", "Permanent"}; 499 legendProps.setLegendLabelsTexts (legendLabels); 500 501 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 503 String [] labelsAxisLabels = {"Windows", "Office", "Visual Dev", ".Net", "Explorer"}; 504 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 505 graphChart2DProps.setLabelsAxisTitleText ("Products"); 506 graphChart2DProps.setNumbersAxisTitleText ("Bugs"); 507 508 GraphProperties graphProps = new GraphProperties(); 510 graphProps.setGraphAllowComponentAlignment (true); 511 graphProps.setGraphBarsRoundingRatio (0f); 512 graphProps.setGraphOutlineComponentsExistence (true); 513 514 Dataset dataset = new Dataset (4, 5, 1); 516 dataset.set (0, 0, 0, 110f); 517 dataset.set (0, 1, 0, 700f); 518 dataset.set (0, 2, 0, 300f); 519 dataset.set (0, 3, 0, 250f); 520 dataset.set (0, 4, 0, 800f); 521 dataset.set (1, 0, 0, 400f); 522 dataset.set (1, 1, 0, 200f); 523 dataset.set (1, 2, 0, 100f); 524 dataset.set (1, 3, 0, 650f); 525 dataset.set (1, 4, 0, 450f); 526 dataset.set (2, 0, 0, 500f); 527 dataset.set (2, 1, 0, 200f); 528 dataset.set (2, 2, 0, 100f); 529 dataset.set (2, 3, 0, 550f); 530 dataset.set (2, 4, 0, 350f); 531 dataset.set (3, 0, 0, 250f); 532 dataset.set (3, 1, 0, 150f); 533 dataset.set (3, 2, 0, 750f); 534 dataset.set (3, 3, 0, 100f); 535 dataset.set (3, 4, 0, 150f); 536 dataset.doConvertToStacked(); 537 538 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 540 541 LBChart2D chart2D = new LBChart2D(); 543 chart2D.setObject2DProperties (object2DProps); 544 chart2D.setChart2DProperties (chart2DProps); 545 chart2D.setLegendProperties (legendProps); 546 chart2D.setGraphChart2DProperties (graphChart2DProps); 547 chart2D.addGraphProperties (graphProps); 548 chart2D.addDataset (dataset); 549 chart2D.addMultiColorsProperties (multiColorsProps); 550 551 if (!chart2D.validate (false)) chart2D.validate (true); 553 554 556 return chart2D; 557 } 558 559 560 564 private Chart2D getChart2DDemoF() { 565 566 568 Object2DProperties object2DProps = new Object2DProperties(); 570 object2DProps.setObjectTitleText ("Programmers By Language"); 571 572 Chart2DProperties chart2DProps = new Chart2DProperties(); 574 575 LegendProperties legendProps = new LegendProperties(); 577 String [] legendLabels = {"C", "C++", "Java"}; 578 legendProps.setLegendLabelsTexts (legendLabels); 579 580 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 582 String [] labelsAxisLabels = 583 {"1990", "1991", "1992", "1993", "1994", "1995", 584 "1996", "1997", "1998", "1999", "2001", "2002"}; 585 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 586 graphChart2DProps.setLabelsAxisTitleText ("Years"); 587 graphChart2DProps.setNumbersAxisTitleText ("Programmers"); 588 graphChart2DProps.setChartDatasetCustomizeGreatestValue (true); 589 graphChart2DProps.setChartDatasetCustomGreatestValue (1000); 590 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 591 592 GraphProperties graphProps = new GraphProperties(); 594 graphProps.setGraphBarsExistence (false); 595 graphProps.setGraphLinesExistence (true); 596 graphProps.setGraphOutlineComponentsExistence (true); 597 graphProps.setGraphAllowComponentAlignment (true); 598 599 Dataset dataset = new Dataset (3, 12, 1); 601 dataset.set (0, 0, 0, 100f); dataset.set (0, 1, 0, 200f); dataset.set (0, 2, 0, 300f); dataset.set (0, 3, 0, 400f); dataset.set (0, 4, 0, 100f); dataset.set (0, 5, 0, 200f); dataset.set (0, 6, 0, 100f); dataset.set (0, 7, 0, 0f); dataset.set (0, 8, 0, 100f); dataset.set (0, 9, 0, 100f); dataset.set (0, 10, 0, 200f); dataset.set (0, 11, 0, 300f); dataset.set (1, 0, 0, 0f); dataset.set (1, 1, 0, 0f); dataset.set (1, 2, 0, 0f); dataset.set (1, 3, 0, 100f); dataset.set (1, 4, 0, 200f); dataset.set (1, 5, 0, 400f); dataset.set (1, 6, 0, 500f); dataset.set (1, 7, 0, 700f); dataset.set (1, 8, 0, 900f); dataset.set (1, 9, 0, 100f); dataset.set (1, 10, 0, 200f); dataset.set (1, 11, 0, 300f); dataset.set (2, 0, 0, 0f); dataset.set (2, 1, 0, 0f); dataset.set (2, 2, 0, 0f); dataset.set (2, 3, 0, 0f); dataset.set (2, 4, 0, 100f); dataset.set (2, 5, 0, 200f); dataset.set (2, 6, 0, 300f); dataset.set (2, 7, 0, 400f); dataset.set (2, 8, 0, 500f); dataset.set (2, 9, 0, 100f); dataset.set (2, 10, 0, 300f); dataset.set (2, 11, 0, 900f); 638 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 640 641 LBChart2D chart2D = new LBChart2D(); 643 chart2D.setObject2DProperties (object2DProps); 644 chart2D.setChart2DProperties (chart2DProps); 645 chart2D.setLegendProperties (legendProps); 646 chart2D.setGraphChart2DProperties (graphChart2DProps); 647 chart2D.addGraphProperties (graphProps); 648 chart2D.addDataset (dataset); 649 chart2D.addMultiColorsProperties (multiColorsProps); 650 651 if (!chart2D.validate (false)) chart2D.validate (true); 653 654 656 return chart2D; 657 } 658 659 660 664 private Chart2D getChart2DDemoG() { 665 666 668 Object2DProperties object2DProps = new Object2DProperties(); 670 object2DProps.setObjectTitleText ("Programmers By Language"); 671 672 Chart2DProperties chart2DProps = new Chart2DProperties(); 674 675 LegendProperties legendProps = new LegendProperties(); 677 String [] legendLabels = {"C", "C++", "Java"}; 678 legendProps.setLegendLabelsTexts (legendLabels); 679 680 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 682 String [] labelsAxisLabels = 683 {"1990", "1991", "1992", "1993", "1994", "1995", 684 "1996", "1997", "1998", "1999", "2001", "2002"}; 685 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 686 graphChart2DProps.setLabelsAxisTitleText ("Years"); 687 graphChart2DProps.setNumbersAxisTitleText ("Programmers"); 688 graphChart2DProps.setChartDatasetCustomizeGreatestValue (true); 689 graphChart2DProps.setChartDatasetCustomGreatestValue (1000); 690 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 691 692 GraphProperties graphProps = new GraphProperties(); 694 graphProps.setGraphBarsExistence (false); 695 graphProps.setGraphLinesExistence (true); 696 graphProps.setGraphAllowComponentAlignment (true); 697 698 Dataset dataset = new Dataset (3, 12, 1); 700 dataset.set (0, 0, 0, 100f); dataset.set (0, 1, 0, 200f); dataset.set (0, 2, 0, 300f); dataset.set (0, 3, 0, 400f); dataset.set (0, 4, 0, 100f); dataset.set (0, 5, 0, 200f); dataset.set (0, 6, 0, 100f); dataset.set (0, 7, 0, 0f); dataset.set (0, 8, 0, 100f); dataset.set (0, 9, 0, 100f); dataset.set (0, 10, 0, 200f); dataset.set (0, 11, 0, 300f); dataset.set (1, 0, 0, 0f); dataset.set (1, 1, 0, 0f); dataset.set (1, 2, 0, 0f); dataset.set (1, 3, 0, 100f); dataset.set (1, 4, 0, 200f); dataset.set (1, 5, 0, 400f); dataset.set (1, 6, 0, 500f); dataset.set (1, 7, 0, 700f); dataset.set (1, 8, 0, 900f); dataset.set (1, 9, 0, 100f); dataset.set (1, 10, 0, 200f); dataset.set (1, 11, 0, 300f); dataset.set (2, 0, 0, 0f); dataset.set (2, 1, 0, 0f); dataset.set (2, 2, 0, 0f); dataset.set (2, 3, 0, 0f); dataset.set (2, 4, 0, 100f); dataset.set (2, 5, 0, 200f); dataset.set (2, 6, 0, 300f); dataset.set (2, 7, 0, 400f); dataset.set (2, 8, 0, 500f); dataset.set (2, 9, 0, 100f); dataset.set (2, 10, 0, 300f); dataset.set (2, 11, 0, 900f); 737 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 739 740 WarningRegionProperties warningRegionProps1 = new WarningRegionProperties(); 742 warningRegionProps1.setHigh (100); 743 warningRegionProps1.setLow (WarningRegionProperties.LOW); 744 745 WarningRegionProperties warningRegionProps2 = new WarningRegionProperties(); 747 warningRegionProps2.setHigh (200); 748 warningRegionProps2.setLow (100); 749 warningRegionProps2.setComponentColor (new Color (146, 105, 0)); 750 warningRegionProps2.setBackgroundColor (new Color (222, 209, 176)); 751 752 LBChart2D chart2D = new LBChart2D(); 754 chart2D.setObject2DProperties (object2DProps); 755 chart2D.setChart2DProperties (chart2DProps); 756 chart2D.setLegendProperties (legendProps); 757 chart2D.setGraphChart2DProperties (graphChart2DProps); 758 chart2D.addGraphProperties (graphProps); 759 chart2D.addDataset (dataset); 760 chart2D.addMultiColorsProperties (multiColorsProps); 761 chart2D.addWarningRegionProperties (warningRegionProps1); 762 chart2D.addWarningRegionProperties (warningRegionProps2); 763 764 if (!chart2D.validate (false)) chart2D.validate (true); 766 767 769 return chart2D; 770 } 771 772 773 777 private Chart2D getChart2DDemoH() { 778 779 781 Object2DProperties object2DProps = new Object2DProperties(); 783 object2DProps.setObjectTitleText ("Programmers By Language"); 784 785 Chart2DProperties chart2DProps = new Chart2DProperties(); 787 chart2DProps.setChartDataLabelsPrecision (2); 788 789 LegendProperties legendProps = new LegendProperties(); 791 String [] legendLabels = {"C", "C++", "Java"}; 792 legendProps.setLegendLabelsTexts (legendLabels); 793 794 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 796 String [] labelsAxisLabels = 797 {"1990", "1991", "1992", "1993", "1994", "1995", 798 "1996", "1997", "1998", "1999", "2001", "2002"}; 799 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 800 graphChart2DProps.setLabelsAxisTitleText ("Years"); 801 graphChart2DProps.setNumbersAxisTitleText ("Programmers"); 802 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 803 804 GraphProperties graphProps = new GraphProperties(); 806 graphProps.setGraphBarsExistence (false); 807 graphProps.setGraphLinesExistence (true); 808 graphProps.setGraphLinesFillInterior (true); 809 graphProps.setGraphLinesThicknessModel (1); 810 graphProps.setGraphAllowComponentAlignment (true); 811 graphProps.setGraphComponentsAlphaComposite (graphProps.ALPHA_COMPOSITE_MEDIUM); 812 813 Dataset dataset = new Dataset (3, 12, 1); 815 dataset.set (0, 0, 0, 100f); dataset.set (0, 1, 0, 200f); dataset.set (0, 2, 0, 300f); dataset.set (0, 3, 0, 400f); dataset.set (0, 4, 0, 100f); dataset.set (0, 5, 0, 200f); dataset.set (0, 6, 0, 100f); dataset.set (0, 7, 0, 0f); dataset.set (0, 8, 0, 100f); dataset.set (0, 9, 0, 100f); dataset.set (0, 10, 0, 200f); dataset.set (0, 11, 0, 300f); dataset.set (1, 0, 0, 0f); dataset.set (1, 1, 0, 0f); dataset.set (1, 2, 0, 0f); dataset.set (1, 3, 0, 100f); dataset.set (1, 4, 0, 200f); dataset.set (1, 5, 0, 400f); dataset.set (1, 6, 0, 500f); dataset.set (1, 7, 0, 700f); dataset.set (1, 8, 0, 900f); dataset.set (1, 9, 0, 100f); dataset.set (1, 10, 0, 200f); dataset.set (1, 11, 0, 300f); dataset.set (2, 0, 0, 0f); dataset.set (2, 1, 0, 0f); dataset.set (2, 2, 0, 0f); dataset.set (2, 3, 0, 0f); dataset.set (2, 4, 0, 100f); dataset.set (2, 5, 0, 200f); dataset.set (2, 6, 0, 300f); dataset.set (2, 7, 0, 400f); dataset.set (2, 8, 0, 500f); dataset.set (2, 9, 0, 100f); dataset.set (2, 10, 0, 300f); dataset.set (2, 11, 0, 900f); dataset.doConvertToStacked(); 852 853 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 855 856 LBChart2D chart2D = new LBChart2D(); 858 chart2D.setObject2DProperties (object2DProps); 859 chart2D.setChart2DProperties (chart2DProps); 860 chart2D.setLegendProperties (legendProps); 861 chart2D.setGraphChart2DProperties (graphChart2DProps); 862 chart2D.addGraphProperties (graphProps); 863 chart2D.addDataset (dataset); 864 chart2D.addMultiColorsProperties (multiColorsProps); 865 866 if (!chart2D.validate (false)) chart2D.validate (true); 868 869 871 return chart2D; 872 } 873 874 875 879 private Chart2D getChart2DDemoI() { 880 881 883 Object2DProperties object2DProps = new Object2DProperties(); 885 object2DProps.setObjectTitleText ("Weekly LOC Programmed"); 886 887 Chart2DProperties chart2DProps = new Chart2DProperties(); 889 chart2DProps.setChartDataLabelsPrecision (1); 890 891 LegendProperties legendProps = new LegendProperties(); 893 String [] legendLabels = {"2001", "2000", "1999"}; 894 legendProps.setLegendLabelsTexts (legendLabels); 895 896 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 898 String [] labelsAxisLabels = 899 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 900 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 901 graphChart2DProps.setLabelsAxisTitleText ("Weeks by Month"); 902 graphChart2DProps.setNumbersAxisTitleText ("LOC"); 903 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 904 905 GraphProperties graphProps = new GraphProperties(); 907 graphProps.setGraphBarsExistence (false); 908 graphProps.setGraphLinesExistence (true); 909 graphProps.setGraphAllowComponentAlignment (true); 910 graphProps.setGraphLinesWithinCategoryOverlapRatio (1f); 911 912 Random random = new Random (); 914 Dataset dataset = new Dataset (3, 12, 4); 915 for (int i = 0; i < dataset.getNumSets(); ++i) { 916 for (int j = 0; j < dataset.getNumCats(); ++j) { 917 for (int k = 0; k < dataset.getNumItems(); ++k) { 918 int increaseMetric = dataset.getNumSets() - i - 1; 919 dataset.set (i, j, k, 920 (increaseMetric + 1) * random.nextInt (5) + (increaseMetric + 1) * 30 + j * 3); 921 } 922 } 923 } 924 925 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 927 928 LBChart2D chart2D = new LBChart2D(); 930 chart2D.setObject2DProperties (object2DProps); 931 chart2D.setChart2DProperties (chart2DProps); 932 chart2D.setLegendProperties (legendProps); 933 chart2D.setGraphChart2DProperties (graphChart2DProps); 934 chart2D.addGraphProperties (graphProps); 935 chart2D.addDataset (dataset); 936 chart2D.addMultiColorsProperties (multiColorsProps); 937 938 if (!chart2D.validate (false)) chart2D.validate (true); 940 941 943 return chart2D; 944 } 945 946 947 951 private Chart2D getChart2DDemoJ() { 952 953 955 Object2DProperties object2DProps = new Object2DProperties(); 957 object2DProps.setObjectTitleText ("Weekly LOC Programmed"); 958 959 Chart2DProperties chart2DProps = new Chart2DProperties(); 961 chart2DProps.setChartDataLabelsPrecision (1); 962 963 LegendProperties legendProps = new LegendProperties(); 965 String [] legendLabels = {"2001", "2000", "1999"}; 966 legendProps.setLegendLabelsTexts (legendLabels); 967 968 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 970 String [] labelsAxisLabels = 971 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 972 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 973 graphChart2DProps.setLabelsAxisTitleText ("Weeks by Month"); 974 graphChart2DProps.setNumbersAxisTitleText ("LOC"); 975 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 976 977 GraphProperties graphProps = new GraphProperties(); 979 graphProps.setGraphBarsExistence (false); 980 graphProps.setGraphDotsExistence (true); 981 graphProps.setGraphAllowComponentAlignment (true); 982 graphProps.setGraphDotsWithinCategoryOverlapRatio (1f); 983 984 Random random = new Random (); 986 Dataset dataset = new Dataset (3, 12, 4); 987 for (int i = 0; i < dataset.getNumSets(); ++i) { 988 for (int j = 0; j < dataset.getNumCats(); ++j) { 989 for (int k = 0; k < dataset.getNumItems(); ++k) { 990 int increaseMetric = dataset.getNumSets() - i - 1; 991 dataset.set (i, j, k, 992 (increaseMetric + 1) * random.nextInt (5) + (increaseMetric + 1) * 30 + j * 3); 993 } 994 } 995 } 996 997 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 999 1000 LBChart2D chart2D = new LBChart2D(); 1002 chart2D.setObject2DProperties (object2DProps); 1003 chart2D.setChart2DProperties (chart2DProps); 1004 chart2D.setLegendProperties (legendProps); 1005 chart2D.setGraphChart2DProperties (graphChart2DProps); 1006 chart2D.addGraphProperties (graphProps); 1007 chart2D.addDataset (dataset); 1008 chart2D.addMultiColorsProperties (multiColorsProps); 1009 1010 if (!chart2D.validate (false)) chart2D.validate (true); 1012 1013 1015 return chart2D; 1016 } 1017 1018 1019 1023 private Chart2D getChart2DDemoK() { 1024 1025 1027 Object2DProperties object2DProps = new Object2DProperties(); 1029 object2DProps.setObjectTitleText ("Monthly LOC Programmed"); 1030 1031 Chart2DProperties chart2DProps = new Chart2DProperties(); 1033 chart2DProps.setChartDataLabelsPrecision (1); 1034 1035 LegendProperties legendProps = new LegendProperties(); 1037 String [] legendLabels = {"2001", "2000", "1999"}; 1038 legendProps.setLegendLabelsTexts (legendLabels); 1039 1040 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 1042 String [] labelsAxisLabels = 1043 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 1044 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 1045 graphChart2DProps.setLabelsAxisTitleText ("Months"); 1046 graphChart2DProps.setNumbersAxisTitleText ("LOC"); 1047 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 1048 1049 GraphProperties graphProps = new GraphProperties(); 1051 graphProps.setGraphBarsExistence (false); 1052 graphProps.setGraphLinesExistence (true); 1053 graphProps.setGraphLinesThicknessModel (2); 1054 graphProps.setGraphLinesWithinCategoryOverlapRatio (1f); 1055 graphProps.setGraphDotsExistence (true); 1056 graphProps.setGraphDotsThicknessModel (10); 1057 graphProps.setGraphDotsWithinCategoryOverlapRatio (1f); 1058 graphProps.setGraphAllowComponentAlignment (true); 1059 1060 Random random = new Random (); 1062 Dataset dataset = new Dataset (3, 12, 1); 1063 for (int i = 0; i < dataset.getNumSets(); ++i) { 1064 for (int j = 0; j < dataset.getNumCats(); ++j) { 1065 for (int k = 0; k < dataset.getNumItems(); ++k) { 1066 int increaseMetric = dataset.getNumSets() - i - 1; 1067 dataset.set (i, j, k, 1068 (increaseMetric + 1) * random.nextInt (5) + (increaseMetric + 1) * 30 + j * 3); 1069 } 1070 } 1071 } 1072 1073 MultiColorsProperties multiColorsProps = new MultiColorsProperties(); 1075 1076 LBChart2D chart2D = new LBChart2D(); 1078 chart2D.setObject2DProperties (object2DProps); 1079 chart2D.setChart2DProperties (chart2DProps); 1080 chart2D.setLegendProperties (legendProps); 1081 chart2D.setGraphChart2DProperties (graphChart2DProps); 1082 chart2D.addGraphProperties (graphProps); 1083 chart2D.addDataset (dataset); 1084 chart2D.addMultiColorsProperties (multiColorsProps); 1085 1086 if (!chart2D.validate (false)) chart2D.validate (true); 1088 1089 1091 return chart2D; 1092 } 1093 1094 1095 1099 private Chart2D getChart2DDemoL() { 1100 1101 1103 Object2DProperties object2DProps = new Object2DProperties(); 1105 object2DProps.setObjectTitleText ("Monthly LOC | Defects Programmed"); 1106 1107 Chart2DProperties chart2DProps = new Chart2DProperties(); 1109 chart2DProps.setChartDataLabelsPrecision (1); 1110 1111 LegendProperties legendProps = new LegendProperties(); 1113 String [] legendLabels = 1114 {"Defects Java", "Defects C++", "Defects C", "LOC Java", "LOC C++", "LOC C"}; 1115 legendProps.setLegendLabelsTexts (legendLabels); 1116 1117 GraphChart2DProperties graphChart2DProps = new GraphChart2DProperties(); 1119 String [] labelsAxisLabels = {"2001", "2000", "1999", "1998"}; 1120 graphChart2DProps.setLabelsAxisLabelsTexts (labelsAxisLabels); 1121 graphChart2DProps.setLabelsAxisTitleText ("Months"); 1122 graphChart2DProps.setNumbersAxisTitleText ("LOC | Defects"); 1123 graphChart2DProps.setLabelsAxisTicksAlignment (graphChart2DProps.CENTERED); 1124 1125 GraphProperties graphPropsLine = new GraphProperties(); 1127 graphPropsLine.setGraphBarsExistence (false); 1128 graphPropsLine.setGraphLinesExistence (true); 1129 graphPropsLine.setGraphAllowComponentAlignment (true); 1130 1131 Random random = new Random (); 1133 Dataset datasetLine = new Dataset (3, 4, 1); 1134 for (int i = 0; i < datasetLine.getNumSets(); ++i) { 1135 for (int j = 0; j < datasetLine.getNumCats(); ++j) { 1136 for (int k = 0; k < datasetLine.getNumItems(); ++k) { 1137 datasetLine.set ( 1138 datasetLine.getNumSets() - 1 - i, j, k, 1139 (i + 1) * random.nextInt (5) + (i + 1) * 30 + j * 3); 1140 } 1141 } 1142 } 1143 1144 MultiColorsProperties multiColorsPropsLine = new MultiColorsProperties(); 1146 multiColorsPropsLine.setColorsType (multiColorsPropsLine.PASTEL); 1147 1148 GraphProperties graphPropsBars = new GraphProperties(); 1150 graphPropsBars.setGraphOutlineComponentsExistence (true); 1151 graphPropsBars.setGraphComponentsAlphaComposite (graphPropsBars.ALPHA_COMPOSITE_MILD); 1152 1153 Dataset datasetBars = new Dataset (3, 4, 1); 1155 for (int i = 0; i < datasetBars.getNumSets(); ++i) { 1156 for (int j = 0; j < datasetBars.getNumCats(); ++j) { 1157 for (int k = 0; k < datasetBars.getNumItems(); ++k) { 1158 datasetBars.set (i, j, k, (i + 1) * random.nextInt (5) + (i + 1) * 30 + j * 3); 1159 } 1160 } 1161 } 1162 1163 MultiColorsProperties multiColorsPropsBars = new MultiColorsProperties(); 1165 1166 LBChart2D chart2D = new LBChart2D(); 1168 chart2D.setObject2DProperties (object2DProps); 1169 chart2D.setChart2DProperties (chart2DProps); 1170 chart2D.setLegendProperties (legendProps); 1171 chart2D.setGraphChart2DProperties (graphChart2DProps); 1172 chart2D.addGraphProperties (graphPropsLine); 1173 chart2D.addDataset (datasetLine); 1174 chart2D.addMultiColorsProperties (multiColorsPropsLine); 1175 chart2D.addGraphProperties (graphPropsBars); 1176 chart2D.addDataset (datasetBars); 1177 chart2D.addMultiColorsProperties (multiColorsPropsBars); 1178 1179 if (!chart2D.validate (false)) chart2D.validate (true); 1181 1182 1184 return chart2D; 1185 } 1186} | Popular Tags |