Bind dataset in a chart

Hello,
I want just load some data from database and show it in a javafx chart.
Since it's not possible to instantiate a javafx app and pass some values like a dataset, it must be possible to bind the data. An example would be great!

That's a really poor design though, IMO. No main(...) method should ever invoke any logic other than creating an object. The business logic should be processed in some kind of business object. That way you can create your business object anywhere you need (in your start(...) method, for example, or in the initialize() method of your controller).
public class DataAccessor {
     public DataAccessor() {
          // ... initialize database connections, etc
     public List<DataObject> getDataObjects() {
          // retrieve data from database
     // other methods as required (update data, etc)
public class Controller {
     private final DataAccessor dataAccessor ;
     // define UI components injected from FXML
     public Controller(DataAccessor dataAccessor) {
          this.dataAccesssor = dataAccessor ;
     public void initialize() {
          // bind data from data accessor to UI Components
public class MyFXApp extends Application {
     @Override
     public void start(Stage primaryStage) throws IOException {
          DataAccessor dataAccessor = new DataAccessor();
          Controller controller = new Controller(dataAccessor) ;
          FXMLLoader loader = new FXMLLoader(getClass().getResource("path/to/fxml/resource");
          loader.setController(controller);
          Scene scene = new Scene((Parent)loader.load());
          primaryStage.setScene(scene);
          primaryStage.show();
     // ignored in most deployment scenarios...
     public static void main(String[] args) {
          launch(args);

Similar Messages

  • When I inherit Form with binding DataSet why then designer find mdb file in 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\'

    When I inherit Form with binding DataSet why then designer find mdb file in 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\' 
    Do I have to anything to change in my application settings or what I am doing wrong?
    When I inherit a plain Form with no binding DataSet then is all ok.

    I finally saw my longingly expected inherited window containing binding dataset.
    But only by way that I put mdb file right in to the this damn path.
    "c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Zdrojove Data\ISMS2003.mdb" 
    In addition mdb file shall be clear too of password.
    We have many windows in our application and we have to work strongly good with inheritance of Form Classes.
    But how I will explain to my Boss if he click on that inherited window and will see this break window?
    Though I will advice to my Boss that hi have to copy too that MDB files to this damn path,
    but the best way could be to find what I need to change that this inherited windows shows without copy this MDB files to
    'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\'
    When I check the settings for DataDirectory every paths looks good.
    Even if I set password for the mdb file I almost see only broken designer window.
    Only by copy this MDB file without his password to this path
    'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\'
     I can see this inherited window right. 

  • Help in Binding list to Flex chart Axis.

    Hi!
    I am doing chart binding in flex. I have a list with Data. I want to separately bind the Y-Axis of chart and then plot line series according to the data in the list.
    Moreover I want to change the background color and border of Data Tip in Flex Chart.
    Regards,
    Nazzal.

    See here:
    http://livedocs.adobe.com/flex/3/html/help.html?content=charts_types_08.html
    There's stuff on data and on customised datatips...

  • No response when binding dataset to the subreport

    Hi,
    Environment:
    OS : Windows 7
    Crystal report for VS2010 (13.0.2)
    Visual Studio 2010 ( using WPF)
    How to bind the loaded dataset to the sub report. I tired in my code the following:
    try{
    rpt.OpenSubreport("SubreportName").SetDataSource(ds);
    Catch(Exception ex)
      MessageBox.WPFMessageBox.Show("error message " + ex.Message);
    While debugging dataset ds is having recordset loaded. When I bind using the above code snippet, no response or some getting error as "load report failed."
    Please help me ASAP.
    Thanks & Regards,
    Mani G.S.

    Hello,
    You can't simply open the subreport....
    Here's code on how to:
    public Form1()
         // Required for Windows Form Designer support
         InitializeComponent();
         // TODO: Add any constructor code after InitializeComponent call
         //Create an instance of the strongly-typed MAIN report object
         crReportDocument = new MainReport();
         //Get all the sections in the report
         crSections = crReportDocument.ReportDefinition.Sections;
         //Loop through each section of the report
         SubNames = "";
         foreach(Section crSection in crSections)
              //Get all the report objects from each section
              crReportObjects = crSection.ReportObjects;
              //Loop through each report object
              foreach(ReportObject crReportObject in crReportObjects)
                   //Check to see if the report object is a subreport
                   if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                        //Found the subreport 
                        //Get the actual subreport object
                        crSubreportObject = (SubreportObject)crReportObject;
                        //Get the subreport as a regular report object 
                        //OpenSubreport returns the subreport object as a report
                        crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
                        //Display the name of the subreport
                        if (SubNames.Length > 0) SubNames += ", ";
                        SubNames = crSubreportDocument.Name;
                   }//Go to the next report object
         }//Go to the next section
         MessageBox.Show("Subreport Names: " + SubNames);
         //Set the viewer to the report object to be previewed
         crystalReportViewer1.ReportSource = crReportDocument;
    Don

  • Chart binded data not showing when Window State property of form is set to Maximized

    Possible bug?
    Using In VS 2013 Community, .NET 4.5, MySQL w/Connector/NET...
    When a form is maximized, it wil not render the binded datasource on a chart.
    Example is a new project...  chart dragged onto a form... add a Dataset when initializing the chart and immediately bind that to the Datasource property with no changes to the chart except changing your XValue from a column to a line type. I only have
    3 columns in the table. keyId, entryDate, mcf.
    I can also maximize the window after the form is up and running and it doesn't effect the chart at all.
    Any ideas? I need the window to run in a maximized state.
    Many thanks!

    Hi,
    to debug your web content in IE
    f12>Debug tab, select "Break on all errors"... the debugger will break on any errors.
    Emulation tab, tells you which emulation mode the browser is using and which userAgent string it is using.
    File>Properties shows which IE security zone it maps to.
    "When a form is maximized it will not render the binded datasource on a chart"
    Probably you are running from a localhost proxy (http://localhost:8080)... the IE developer tool will show you any scripting errors. Publish your 'test' to a named webserver. eg.
    http://localhost/test.local
    - Questions about html, css and scripting for website developers. If possible please include with your question a link to your website or a mashup that shows the issue.
    Regards.
    Rob^_^

  • How to bind bar chart(columns) to array list object in c# win form

    how to bind bar chart(columns) to array list  object in c#win form

    Hi Ramesh,
    Did you want to bind list object to bar chart? I made a simple code to achieve binding list to bar chart.
    public partial class Form0210 : Form
    public Form0210()
    InitializeComponent();
    private void Form0210_Load(object sender, EventArgs e)
    BindData();
    public void BindData()
    List<int> yValues = new List<int>(new int[] { 20, 30, 10, 90, 50 });
    List<string> xValues = new List<string>(new string[] { "1:00", "2:00", "3:00", "4:00", "5:00" });
    chart1.Series[0].Points.DataBindXY(xValues, yValues);
    The links below might be useful to you:
    # Data Binding Microsoft Chart Control
    http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
    # Series and Data Points (Chart Controls)
    https://msdn.microsoft.com/en-us/library/vstudio/dd456769(v=vs.100).aspx
    In addition, if I misunderstood you, please share us more information about your issue.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • SSRS 2008: how to show an empty chart with legend and x and y axis when no data available

    Hi,
    I am using SSRS 2008, I generated one chart in report designer with the data from Analysis Services (Cube).
    According to the dataset, there is no data returned when I run the query. so when I preview the chart, there is nothing but "no data available" showing on the chart.
    Here I want to know is there any possible to show an empty chart with legend and x and y axis?
    If it is possible, can you tell me how can I make it?
    Best Regards.
    Connie Zhu

    Hi,
    When there is no data, the chart displays the message "no data available". But using a little work around, you can display an empty chart.
    Please find the below steps given to achieve this
    1. Create a new dataset using TSQL to return 1 row of data having the category field and value field set to 0. Add the fields that are necessary for the category fields, series fields and datafields.
       A simple example would be like
       SELECT 'abc' as Category, 0 as Amount
    2. Add a new chart, set the category field to 'Category' and set the data field to Amount from above dataset created in step 1.
    3. In the new chart, right click the category axis and select axis properties, Click on the labels tab, check on
    'Hide axis labels' and then click ok
    4. Now set the Visibility property of both the charts depending on the rows returned from your main dataset
       a. click on your main chart and set its Hidden property to :
    =iif(CountRows("MainDataSet"),false,true) 
       b. click on the new blank chart added and set its Hidden proprety to (the opposite) :
    =iif(CountRows("MainDataSet"),true,false) 
       Note : Please change the dataset name in above expression "MainDataset" to the name of your chart's dataset
    5. Resize the new chart to the same size as your main chart, then position the new chart on the place as the main chart.
       (Note : You can set the position of new chart to be same by copying the location property from the main chart) 
    6. Now run and observe the result. When there are no rows returned by your main dataset, the new chart (the blank chart) should be displayed.
    I've added a working sample of this kind of a report
    here.
    Hope this helps. Please feel free to discuss if you have any questions.
    Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.
    BH

  • Width of stack chart not getting retained in Flex 4 but working in Flex3

    I have a stack chart on  my dashboard when I click on stack chart it become a column chart. When I trying  to come back on stack chart by clicking on column chart the width of columns of  stack chart does not match with the previous stack  chart.
    Note: The same code is  working fine in flex 3 version.
    How can I maintain the  same width in both stack charts in flex 4 as it is performing in  flex3?
    Step 1 Monthly stack chart.
    Initially when I click on the equipment break down checkbox the stack chart appears as shown in the below screen shot.
    Step 2: Monthly chart: Then when I click on the above “Monthly stack chart”, then I resume to my original bar chart appearance as shown in the below screenshot.
    Step 3: Monthly stack chart: Further when I click on the above “Monthly chart” bar chart and move back to the “monthly stack chart” it appears as in the below screen shot in flex 4. The width of the chart in step 3 does not match with the width in step 1 of “Monthly Stack Chart”.
    Note: In flex 3 the same step 3 appears to be as shown in the below screenshot.
    How can I maintain the same width in step 1 and step 3 charts in flex 4 as it is performing in flex3?
    CODE:
    /* When click on column chart */
    private function chartDrillDown(e:ChartItemEvent):void
    {var colsr:ColumnSeries;
        If (chkEquipmentBreakdown.selected) Then
           {    loadBreakdownDataForMonth((e.hitData.chartItem.index)+1);
                         IsMonthly=true;
        Else
                DrillState=e;
                  DrillLevel= DrillLevel==0?1:0;   
                      if(DrillLevel==1)
                      {chkDEMO.selected=false;
                            LastValidatedBox.visible=false;
                          siteid = e.hitData.item.VLD_SITE_ID;
                         var obj:Object=e.hitData.item;
                colsr = ColumnSeries(e.hitData.element)
                         strassetname = obj[strTitleField].toString();
                         drillToIndex = e.hitData.item.VLD_SITE_ID;
                        viewequivalentBreakdown();
                        fromAssetToMonthly=true;
                        loadMonthlyData(siteid);
            Else
                      {     if(fromAssetToMonthly==true)
         DrillLevel=DrillLevel==1?0:1;
                          else
                            LastValidatedBox.visible=true;
                colsr = ColumnSeries(e.hitData.element)
                           siteid="-1";
                           ShowHideEquipmentBreakdown(false);
                            loadYearlyData();
                If (IsMonthly) Then
                                  onchkEquipmentBreakdownChange();
                            IsMonthly=false;
    /* Bind data To column chart */
    private function onDataLoadComplete(event:ResultEvent):void
    {                                   webServ.removeEventListener(ResultEvent.RESULT,onDataLoadComplete);                
                      var resultArr:Array = event.result.toString().split("^");
                      xmlData = new XML(resultArr[0]);
                      xmlSeries= new XML(resultArr[1]);              
                      xmlColumns=new XML(resultArr[2]);
                      if(resultArr[3]!=null)
                      {     xmlValidatedData = new XML(resultArr[3]);
                            arrSeries=createSeries(xmlSeries,xmlValidatedData);
        Else
                            arrSeries=creatSeries(xmlSeries);
                      //chart properties
                      //arrSeries=creatSeries(xmlSeries);
                      colChart.series=arrSeries;
                    arrcalc=arrSeries;
                      /*if equipment break down check box checked*/
            If (chkEquipmentBreakdown.selected) Then
                      {colChart.type="stacked";
            Else
                            colChart.type="clustered";
                      colChart.dataProvider=xmlData.Table;
                      cursorManager.removeBusyCursor();
    /* function for load the step 1 and 3 "monthly stack chart".*/
    private function onchkEquipmentBreakdownChange():void
                      colsrs.setStyle("showDataEffect", zoomOut);    
        If (chkEquipmentBreakdown.selected) Then
                      {  GHGDemo.visible=false;
                            AtmosBox.visible=false;
                            chkCompareYear.enabled=false;
                            cursorManager.setBusyCursor();
                            webServ.addEventListener(ResultEvent.RESULT, onDataLoadComplete);
                            if(strTitle==strTitle1)
                                  if(GHGGROSS.selected==true)
                                        webOper = webServ.getOperation("LoadGHGDataMonthlyBreak") as Operation;
                    webOper.send(userid,selectedYear,siteid);
                Else
                                        webOper = webServ.getOperation("LoadGHGMonthlyBreak") as Operation;
                    webOper.send(userid,selectedYear,siteid);
    /* function for load the step 2 "Monthly chart".*/
      private function loadBreakdownDataForMonth(monthnum:int):void
          {   var dayNum:uint = monthnum;
                cursorManager.setBusyCursor();
                      webServ.addEventListener(ResultEvent.RESULT, onDataLoadComplete);
                      var atmosflag:Boolean;
                      var ghggrossflag:Boolean;
                      atmosflag=false;
                      ghggrossflag=false;
                      if(strTitle==strTitle1)
                                  if(GHGGROSS.selected==true)
                                        webOper = webServ.getOperation("LoadGHGDataMonthWiseGross") as Operation;
                            webOper.send(userid,selectedYear,siteid,monthnum);
                                        ghggrossflag=true;
            Else
                                        webOper = webServ.getOperation("LoadGHGBreakDownDataMonthWiseNet") as Operation;
                           webOper.send(userid,selectedYear,siteid,monthnum);
    <mx:ColumnChart id="colChart" itemClick="chartDrillDown(event)"  dataTipFunction="dtFunc">
            <mx:horizontalAxis>
               <mx:CategoryAxis  id="catAxis"  />
                      </mx:horizontalAxis>
                <mx:verticalAxis>
                  <mx:LinearAxis id="lnrAxis" baseAtZero="true" minimum="0" title="" labelFunction="defineVerticalLabel"/>
                </mx:verticalAxis>     
                <mx:horizontalAxisRenderers>
                <mx:AxisRenderer   axis="{catAxis}" labelRotation="45">
                </mx:AxisRenderer>
          </mx:horizontalAxisRenderers>
      </mx:ColumnChart>    

    Thanks for your reply,
    I am using the Adobe flash builder 4 and the Adobe flash player 10. To upgrade from flex 3 to flex 4 I just opened the project in flex 4.I am using the default skins/themes of Adobe flash builder 4.
    But it is not working as flex 3. Please suggest some other option.
    Thanks...

  • While Loop in Gantt Chart Value

    the problem is in the "createDataset" method whereby i want to do a while loop where i can check the data inside the database that i just inserted. after that i want to pass in all the data that is needed to generate the Gantt Chart. can anyone help me on this?
    thanks
    package ericTest;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.text.ParseException;
    import java.util.StringTokenizer;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.Calendar;
    import java.util.Date;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.data.category.IntervalCategoryDataset;
    import org.jfree.data.gantt.Task;
    import org.jfree.data.gantt.TaskSeries;
    import org.jfree.data.gantt.TaskSeriesCollection;
    import org.jfree.data.time.SimpleTimePeriod;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    import com.db4o.Db4o;
    import com.db4o.ObjectContainer;
    import com.db4o.ObjectSet;
    public class GanttDemo3 extends ApplicationFrame {
       public GanttDemo3(final String title) {
            super(title);
            final IntervalCategoryDataset dataset = createDataset();
            final JFreeChart chart = createChart(dataset);
            // add the chart to a panel...
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
             public final static String filename = "C:\\KLGCC Mock Up.yap";
             private static ObjectContainer db;
             private static String day;
             private static String month;
             private static String year;
             private static String task;
             private static String startDate;
             private static String endDate;
             private static String startDay;
             private static String startMonth;
             private static String startYear;
             public static int startDay1;
             public static int startMonth1;
             public static int startYear1;
             public static String endDay;
             public static String endMonth;
             public static String endYear;
             public static int endDay1;
             public static int endMonth1;
             public static int endYear1;
             DataInputStream dis = null;
             String fileRecord = null;
             public void storeData() throws IOException{
                  new File(filename).delete();
                  db = Db4o.openFile(filename);
                       File f = new File("C:\\KLGCC Mock Up.txt");
                       FileReader fis = new FileReader(f);
                       BufferedReader bis = new BufferedReader(fis);
                       while((fileRecord = bis.readLine()) != null){
                                 StringTokenizer st = new StringTokenizer(fileRecord,",");
                                 task = st.nextToken();
                                 startDate = st.nextToken();
                                 endDate = st.nextToken();
                                 System.out.println(task+ " - " +startDate+ " - " +endDate);
                                 Country c = new Country(task, startDate, endDate);
                                 db.set(c);               
                       db.close();
             public void storeStartDate() throws ParseException{
                  db = Db4o.openFile(filename);
                  Country c = new Country();
                  ObjectSet result = db.get(c);
                  while(result.hasNext()){
                       Country obj = (Country)result.next();
                       String sDate = obj.getStartDate();
                       StringTokenizer str = new StringTokenizer(sDate, "/");
                       startMonth = str.nextToken();
                       startDay = str.nextToken();
                       startYear = str.nextToken();
                       System.out.println(startYear);
                       int startMonth1 = Integer.parseInt(startMonth);
                       int startDay1 = Integer.parseInt(startDay);
                       int startYear1 = Integer.parseInt(startYear);
                       //startMonth1 = startMonth1 + 1;
                       ArrayList<Integer> startDay2 = new ArrayList<Integer>();
                       startDay2.add(startDay1);
                       ArrayList<Integer> startMonth2 = new ArrayList<Integer>();
                       startMonth2.add(startMonth1);
                       ArrayList<Integer> startYear2 = new ArrayList<Integer>();
                       startYear2.add(startYear1);
                       System.out.println("Heloo" +startDay2+ "/" +startMonth2+ "/" +startYear2);
                  db.close();          
        public void storeEndDate() throws ParseException{
                  db = Db4o.openFile(filename);
                  Country c = new Country();
                  ObjectSet result = db.get(c);
                  while(result.hasNext()){
                       Country obj = (Country)result.next();
                       String sEndDate = obj.getEndDate();
                       StringTokenizer str1 = new StringTokenizer(sEndDate, "/");
                       endMonth = str1.nextToken();
                       endDay = str1.nextToken();
                       endYear = str1.nextToken();
                       int endMonth1 = Integer.parseInt(endMonth);
                       int endDay1 = Integer.parseInt(endDay);
                       int endYear1 = Integer.parseInt(endYear);
                       ArrayList<Integer> endDay2 = new ArrayList<Integer>();
                       endDay2.add(startDay1);
                       ArrayList<Integer> endMonth2 = new ArrayList<Integer>();
                       endMonth2.add(endMonth1);
                       ArrayList<Integer> endYear2 = new ArrayList<Integer>();
                       endYear2.add(endYear1);
                       System.out.println("END" +endDay2+ "/" +endMonth2+ "/" +endYear2);
                  db.close();
        public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             //Country chart = new Country();
             ArrayList ar = new Arraylist;
             Iterator it = ar.iterator();
             while it.hasNext();{
             s1.add(new Task("abc",
                   new SimpleTimePeriod(date(startDay1, startMonth1, startYear1),
                                        date(endDay1, endMonth1, endYear1))));
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
         * Utility method for creating <code>Date</code> objects.
         * @param day  the date.
         * @param month  the month.
         * @param year  the year.
         * @return a date.
        private static Date date(final int day, final int month, final int year) {
            final Calendar calendar = Calendar.getInstance();
            calendar.set(year, month, day);
            final Date result = calendar.getTime();
            return result;
         * Creates a chart.
         * @param dataset  the dataset.
         * @return The chart.
        private JFreeChart createChart(final IntervalCategoryDataset dataset) {
            final JFreeChart chart = ChartFactory.createGanttChart(
                "Gantt Chart Demo",  // chart title
                "Task",              // domain axis label
                "Date",              // range axis label
                dataset,             // data
                true,                // include legend
                true,                // tooltips
                false                // urls
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
            return chart;   
        public static void main(final String[] args) throws IOException, ParseException
            final GanttDemo3 demo = new GanttDemo3("Gantt Chart Demo 1");
            demo.storeData();
            demo.storeStartDate();
            demo.storeEndDate();
            demo.pack();
            RefineryUtilities.centerFrameOnScreen(demo);
            demo.setVisible(true);
    }

    sorry. i know it's kinda blurr.
    i did some modification on this part of the code
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             //Country chart = new Country();
             ArrayList ar = new ArrayList();
             for (Iterator it = ar.iterator(); it.hasNext();)
             s1.add(new Task(task,
                   new SimpleTimePeriod(date(startDay1, startMonth1, startYear1),
                                        date(endDay1, endMonth1, endYear1))));
             System.out.println(task);
            final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
             }the problem is the gantt chart after i have generated couldn't come out any value. is it because i never executed some methods?
    thanks

  • Need to pass information from MS access database to another prog

    Hi,
    I really need some help here...
    I need to pass selected information from my database to another information.
    I am able to select and display the infotmation but i am not sure how i can transfer the information to the next program. Can any one please offer me some assistance?
    My code is as follow:
    /* Getting data from PSM32 and displaying it *can work* */
    import java.net.URL;
    import java.sql.*;
    import java.lang.String;
    /** Application to create a Ganttchart * */
    public class PSMdb
    public static void main (String argv[])
    //SQLQueryFormat a = new SQLQueryFormat();
    System.out.println("\nEstablishing Connection - Pls Wait... \n");
    /** Get Info fr database**/
    try
         //Connect to the database specified in the URL
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:PSM32");
         System.out.println("Connection Established.\n");
         //Create a SELECT statement object
         Statement statmt = con.createStatement();
         //Issue the SELECT statement
         String querySt = "SELECT Set, Name, Order " +
         "FROM PMETERS " +
         "WHERE Set = 'BRAKE.BAK' ";
         //Create and execute query
         ResultSet res = statmt.executeQuery(querySt);
           while (res.next())
                String Proj = res.getString(1); //get Proj Name
              String Task = res.getString(2); //get Task Name
              //Print statement
              System.out.println("" +Proj);
              System.out.println("" +Task);
           //Close Statement and Connection
         statmt.close();
         con.close();
         System.out.println("\nConnection Closed - Operation Successful.");
         catch(Exception E)
    //Print out the Exception Error
    System.out.println("Error:" +E );
    }And yes there is another problem. I can compile and run the program in a C:\folder but when i open the document in a project workspace, i cant compile the above code. Can any one please offer me assistance?
    Thanks a million.

    To NanookOITheNorth:
    Could you provide some more relevent information
    about what the other program is and how data should
    be transferred to it? API? Socket? File?was wanted to use the "return task" thing. Issit possible to use that?
    To annie79:
    my next program is supposed to retrive the events in the "task" field and display it in a applet. After retriving the tasks i will be getting the dates to produce the gantt chart. uses the jfree lib functions.
    the code for the applet is as follow
    /* original gantt chart program that can work*/
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.Calendar;
    import java.util.Date;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.data.category.IntervalCategoryDataset;
    import org.jfree.data.gantt.Task;
    import org.jfree.data.gantt.TaskSeries;
    import org.jfree.data.gantt.TaskSeriesCollection;
    import org.jfree.data.time.SimpleTimePeriod;
    /** Application to create a Ganttchart * */
    public class Ganttchart extends JApplet{
    /** @param title , frame title **/
        public void init() {
            final IntervalCategoryDataset dataset = createDataset();
            final JFreeChart chart = createChart(dataset);
            // add the chart to a panel...
            final ChartPanel chartPanel = new ChartPanel(chart);
            // this size (500, 270) here doesn't matter cos this become the html control
            // how big u wan can change in the html code the width="800" height="600"
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
         * Creates a sample dataset for a Ganttchart.
         * @return The dataset.
        public static IntervalCategoryDataset createDataset() {
         //"Task" information should be retrived from the database to replace this current 1
            /*final TaskSeries s1 = new TaskSeries("Scheduled");
            s1.add(new Task("Write Proposal",
                   new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
                                        date(5, Calendar.APRIL, 2001))));
            s1.add(new Task("Obtain Approval",
                   new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
                                        date(9, Calendar.APRIL, 2001))));
            s1.add(new Task("Requirements Analysis",
                   new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
                                        date(5, Calendar.MAY, 2001))));
            final TaskSeries s2 = new TaskSeries("Actual");
            s2.add(new Task("Write Proposal",
                   new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
                                        date(5, Calendar.APRIL, 2001))));
            s2.add(new Task("Obtain Approval",
                   new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
                                        date(9, Calendar.APRIL, 2001))));
            s2.add(new Task("Requirements Analysis",
                   new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
                                        date(15, Calendar.MAY, 2001))));*/
            final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            collection.add(s2);
            return collection;
         * Utility method for creating <code>Date</code> objects.
         * @param day  the date.
         * @param month  the month.
         * @param year  the year.
         * @return a date.
        private static Date date(final int day, final int month, final int year) {
            final Calendar calendar = Calendar.getInstance();
            calendar.set(year, month, day);
            final Date result = calendar.getTime();
            return result;
         * Creates a chart.
         * @param dataset  the dataset.
         * @return The chart.
        private JFreeChart createChart(final IntervalCategoryDataset dataset) {
            final JFreeChart chart = ChartFactory.createGanttChart(
                "Ganttchart",  // chart title
                "Task",              // domain axis label
                "Date",              // range axis label
                dataset,             // data
                true,                // include legend
                true,                // tooltips
                false                // urls
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
            return chart;   
    }As for the "run the program in a C:\folder but when i open the
    document in a project workspace, i cant compile the
    above code. Can any one please offer me assistance?"The run time error that i get is "java.lang.NoSuchMethodError: main
    Exception in thread "main" "
    Please give me some leads on how i can cont to proceed?
    Thanks a lot

  • I wanna dots instead of displaying it as a whole line in Linechart

    Hi Folks,
    I had one small doubt in the output of this program. The program is related to LineChart..Actually, Im getting the output as Line in the chart, but my requirement is to display only dots instead of displaying as a line...
    I just want only displaying as dots at particular name, insteading of getting that whole line from beginning to end...
    First of all whether its posiible to get dots or not?? and if it is possible, how??
    Here is the code:
    package com.home.practise.streams;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Polygon;
    import java.awt.Shape;
    import java.awt.geom.Rectangle2D;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.DefaultDrawingSupplier;
    import org.jfree.chart.plot.DrawingSupplier;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.renderer.category.LineAndShapeRenderer;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    public class LineChartDemo5 extends ApplicationFrame {
        public LineChartDemo5(final String title) {
            super(title);
            final CategoryDataset dataset = createDataset();
            final JFreeChart chart = createChart(dataset);
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
        private CategoryDataset createDataset() {
            // row keys...
            final String series1 = "First";
            final String series2 = "Second";
            final String series3 = "Third";
            // column keys...
            final String type1 = "Hari";
            final String type2 = "Chary";
            final String type3 = "Trinetra";
            final String type4 = "Naveen";
            final String type5 = "Type 5";
            final String type6 = "Type 6";
            final String type7 = "Type 7";
            final String type8 = "Type 8";
            // create the dataset...
            final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            dataset.addValue(0, series1, type1);
            dataset.addValue(0, series1, type2);
            dataset.addValue(1, series1, type3);
            dataset.addValue(1, series1, type4);
            /*dataset.addValue(5.0, series1, type5);
            dataset.addValue(7.0, series1, type6);
            dataset.addValue(7.0, series1, type7);
            dataset.addValue(8.0, series1, type8);*/
            /*dataset.addValue(5.0, series2, type1);
            dataset.addValue(7.0, series2, type2);
            dataset.addValue(6.0, series2, type3);
            dataset.addValue(8.0, series2, type4);
            dataset.addValue(4.0, series2, type5);
            dataset.addValue(4.0, series2, type6);
            dataset.addValue(2.0, series2, type7);
            dataset.addValue(1.0, series2, type8);
            dataset.addValue(4.0, series3, type1);
            dataset.addValue(3.0, series3, type2);
            dataset.addValue(2.0, series3, type3);
            dataset.addValue(3.0, series3, type4);
            dataset.addValue(6.0, series3, type5);
            dataset.addValue(3.0, series3, type6);
            dataset.addValue(4.0, series3, type7);
            dataset.addValue(3.0, series3, type8);*/
            return dataset;
        private JFreeChart createChart(final CategoryDataset dataset) {
            final JFreeChart chart = ChartFactory.createLineChart(
                "visualization",      // chart title
                "Names",                   // domain axis label
                "Gender",                  // range axis label
                dataset,                  // data
                PlotOrientation.VERTICAL, // orientation
                true,                     // include legend
                true,                     // tooltips
                false                     // urls
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
      //      legend.setDisplaySeriesShapes(true);
            final Shape[] shapes = new Shape[3];
            int[] xpoints;
            int[] ypoints;
            // right-pointing triangle
            xpoints = new int[] {-3, 3, -3};
            ypoints = new int[] {-3, 0, 3};
            shapes[0] = new Polygon(xpoints, ypoints, 3);
            // vertical rectangle
            shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);
            // left-pointing triangle
            xpoints = new int[] {-3, 3, 3};
            ypoints = new int[] {0, -3, 3};
            shapes[2] = new Polygon(xpoints, ypoints, 3);
            final DrawingSupplier supplier = new DefaultDrawingSupplier(
                DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                shapes
            final CategoryPlot plot = chart.getCategoryPlot();
            plot.setDrawingSupplier(supplier);
            chart.setBackgroundPaint(Color.yellow);
            // set the stroke for each series...
            plot.getRenderer().setSeriesStroke(
                0,
                new BasicStroke(
                    2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] {10.0f, 6.0f}, 0.0f
            plot.getRenderer().setSeriesStroke(
                1,
                new BasicStroke(
                    2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] {6.0f, 6.0f}, 0.0f
            plot.getRenderer().setSeriesStroke(
                2,
                new BasicStroke(
                    2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] {2.0f, 6.0f}, 0.0f
            // customise the renderer...
            final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);
            renderer.setItemLabelsVisible(true);
         //   renderer.setSeriesLinesVisible(0, false);
       //     renderer.setBaseLinesVisible(false);
      //      renderer.setBaseShapesVisible(true);
      //      renderer.setSeriesLinesVisible(1, true);
      //      renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
            // customise the range axis...
            final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setAutoRangeIncludesZero(false);
            rangeAxis.setUpperMargin(0.12);
            return chart;
        public static void main(final String[] args) {
            final LineChartDemo5 demo = new LineChartDemo5("Line Chart Demo 5");
            demo.pack();
            RefineryUtilities.centerFrameOnScreen(demo);
            demo.setVisible(true);
    }And here is the link, I have just used the above program from this link only
    http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm

    It looks like you're using BasicStrokes to create dashed lines
    plot.getRenderer().setSeriesStroke(
        0,
        new BasicStroke(
            2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] {10.0f, 6.0f}, 0.0f
    plot.getRenderer().setSeriesStroke(
        1,
        new BasicStroke(
            2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] {6.0f, 6.0f}, 0.0f
    plot.getRenderer().setSeriesStroke(
        2,
        new BasicStroke(
            2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] {2.0f, 6.0f}, 0.0f
    ); Is this not what you want? If you want points instead of dashes you just specify *1f* for first argument in the float array
    new BasicStroke(...,...,...,...,new float[]{1f,6f},....); That indicates that you want the dashed regions to be ~1 pixel long - that is, a point - and the empty regions between the dashes to be ~6 pixels long.

  • How can I include a file in a servlet?

    I need to include a header file in htm format and a footer as well. My question here is, is it possible to include these files when a servlet is executed? like in the cases of the jsp web apps, with the <%@include file = "header.htm"%> tag... please let me know and thanks in advance.
    Regards

    Use RequestDispatcher.include:
    RequestDispatcher rd =
    = this.getServletContext().getRequestDispatcher(url);
    try { rd.include(request, response); }
    catch (Exception e) { "Error : Dispatch includeError
    : " + e); }Where url is the relative url of the HTML file.Hi, thanks for your answer, I still having a problem there, I used the RequestDispatcher.Include but it didn't show the file this is the code I'm trying to use:
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    OutputStream out = response.getOutputStream();
    RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/form.htm");
    try {
    rd.include(request, response);
    catch (Exception e)
    System.out.println("Error : Dispatch includeError : " + e);
    try {
    IntervalCategoryDataset dataset = createGanttDataset();
    System.out.println("Total Categories: " + dataset.getCategoryCount());
    System.out.println("Total series: " + dataset.getSeriesCount());
         JFreeChart chart = ChartFactory.createGanttChart("Activities for F3319G1", "Activity", "Date", dataset, true);
    response.setContentType("image/png");
         ChartUtilities.writeChartAsPNG(out, chart, 800, 600);
    catch (Exception e) {
    e.printStackTrace();
    System.err.println(e.toString());
    finally {
    out.close();
    This servlet gets an image.. so the ContentType is set to "image/png" I don't know if this is causing the problem in such case what would I need to include an html or htm file in this kind of servlet? thanks in advance.
    Regards

  • Date/Time on X-Axis with JFreeChart

    Hi guys,
    I've asked this question on the JFreeChart forums, but got no response.
    If anyone has any experience with JFreeChart, help would be most appreaciated.
    I am drawing a XY Line Chart to display CPU usage retrieved from a database. The user can search with specific dates/times (eg: from: 24/2/2005 to: 16/4/2005) - and then these results would be graphed.
    My question is, how do I use dates/times on the X-axis using JFreeChart?
    The results I am getting from the DB would be a time-stamp and CPU usage.
    Here is my current code, but it wont work with a time-stamp:
    public static class ChartTest   {
        public ChartTest()
            // create a dataset...FOR LOOP
            XYSeries dataSet = new XYSeries("CPU Usage");
            TimeSeries closing = new TimeSeries( "Closing Value", Day.class );
         for(int h=0; h < newArray[0].length; h++)
            for(int i=0; i < newArray.length; i++)
               dataSet.add(newArray[i][h], newArray[i][h++]);
            XYDataset xyDataset = new XYSeriesCollection(dataSet);
            // create a chart...
            JFreeChart lineGraph = ChartFactory.createXYLineChart
                        ("Mitch's CPU Usage Test",  // Title
                          "Time",           // X-Axis label
                          "CPU Load",           // Y-Axis label
                          xyDataset,          // Dataset
                          PlotOrientation.VERTICAL,        //Plot orientation
                          true,                //show legend
                          true,                // Show tooltips
                          false               //url show
            // create and display a frame...
            ChartFrame frame = new ChartFrame("CPU Usage Test", lineGraph);
            frame.pack();
            frame.setVisible(true);
        }

    The JFreeChard demo should give you the idea
    package demo;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.text.SimpleDateFormat;
    import javax.swing.JPanel;
    import org.jfree.chart.*;
    import org.jfree.chart.axis.DateAxis;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.time.*;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.*;
    public class TimeSeriesDemo1 extends ApplicationFrame
        public TimeSeriesDemo1(String s)
            super(s);
            XYDataset xydataset = createDataset();
            JFreeChart jfreechart = createChart(xydataset);
            ChartPanel chartpanel = new ChartPanel(jfreechart, false);
            chartpanel.setPreferredSize(new Dimension(500, 270));
            chartpanel.setMouseZoomable(true, false);
            setContentPane(chartpanel);
        private static JFreeChart createChart(XYDataset xydataset)
            JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, true, true, false);
            jfreechart.setBackgroundPaint(Color.white);
            XYPlot xyplot = (XYPlot)jfreechart.getPlot();
            xyplot.setBackgroundPaint(Color.lightGray);
            xyplot.setDomainGridlinePaint(Color.white);
            xyplot.setRangeGridlinePaint(Color.white);
            xyplot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
            xyplot.setDomainCrosshairVisible(true);
            xyplot.setRangeCrosshairVisible(true);
            org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
            if(xyitemrenderer instanceof XYLineAndShapeRenderer)
                XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
                xylineandshaperenderer.setDefaultShapesVisible(true);
                xylineandshaperenderer.setDefaultShapesFilled(true);
            DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
            dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
            return jfreechart;
        private static XYDataset createDataset()
            TimeSeries timeseries = new TimeSeries("L&G European Index Trust", org.jfree.data.time.Month.class);
            timeseries.add(new Month(2, 2001), 181.8);
            timeseries.add(new Month(3, 2001), 167.3);
            timeseries.add(new Month(4, 2001), 153.8);
            timeseries.add(new Month(5, 2001), 167.6);
            timeseries.add(new Month(6, 2001), 158.8);
            timeseries.add(new Month(7, 2001), 148.3);
            timeseries.add(new Month(8, 2001), 153.9);
            timeseries.add(new Month(9, 2001), 142.7);
            timeseries.add(new Month(10, 2001), 123.2);
            timeseries.add(new Month(11, 2001), 131.8);
            timeseries.add(new Month(12, 2001), 139.6);
            timeseries.add(new Month(1, 2002), 142.9);
            timeseries.add(new Month(2, 2002), 138.7);
            timeseries.add(new Month(3, 2002), 137.3);
            timeseries.add(new Month(4, 2002), 143.9);
            timeseries.add(new Month(5, 2002), 139.8);
            timeseries.add(new Month(6, 2002), 137.0);
            timeseries.add(new Month(7, 2002), 132.8);
            TimeSeries timeseries1 = new TimeSeries("L&G UK Index Trust", org.jfree.data.time.Month.class);
            timeseries1.add(new Month(2, 2001), 129.6);
            timeseries1.add(new Month(3, 2001), 123.2);
            timeseries1.add(new Month(4, 2001), 117.2);
            timeseries1.add(new Month(5, 2001), 124.1);
            timeseries1.add(new Month(6, 2001), 122.6);
            timeseries1.add(new Month(7, 2001), 119.2);
            timeseries1.add(new Month(8, 2001), 116.5);
            timeseries1.add(new Month(9, 2001), 112.7);
            timeseries1.add(new Month(10, 2001), 101.5);
            timeseries1.add(new Month(11, 2001), 106.1);
            timeseries1.add(new Month(12, 2001), 110.3);
            timeseries1.add(new Month(1, 2002), 111.7);
            timeseries1.add(new Month(2, 2002), 111.0);
            timeseries1.add(new Month(3, 2002), 109.6);
            timeseries1.add(new Month(4, 2002), 113.2D);
            timeseries1.add(new Month(5, 2002), 111.6);
            timeseries1.add(new Month(6, 2002), 108.8);
            timeseries1.add(new Month(7, 2002), 101.6);
            TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
            timeseriescollection.addSeries(timeseries);
            timeseriescollection.addSeries(timeseries1);
            timeseriescollection.setDomainIsPointsInTime(true);
            return timeseriescollection;
        public static JPanel createDemoPanel()
            JFreeChart jfreechart = createChart(createDataset());
            return new ChartPanel(jfreechart);
        public static void main(String args[])
            TimeSeriesDemo1 timeseriesdemo1 = new TimeSeriesDemo1("Time Series Demo 1");
            timeseriesdemo1.pack();
            RefineryUtilities.centerFrameOnScreen(timeseriesdemo1);
            timeseriesdemo1.setVisible(true);
    }

  • Save  applet  as  images

    I create graphical report using jfree chart . it gives output in applet now i want to save applet as jpg image .
    is it possible ?
    i tried but i got image contain only black color.
    here is my code.
    package com.webaccess.wasurvey.action;
    import com.lowagie.text.Image;
    import java.awt.image.BufferedImage;
    import java.awt.image.ImageObserver;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.CategoryAxis;
    import org.jfree.chart.axis.CategoryLabelPosition;
    import org.jfree.chart.axis.CategoryLabelPositions;
    import org.jfree.chart.axis.CategoryLabelWidthType;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.text.TextBlockAnchor;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RectangleAnchor;
    import org.jfree.ui.RefineryUtilities;
    import org.jfree.ui.TextAnchor;
    import org.jfree.util.Log;
    import org.jfree.util.PrintStreamLogTarget;
    * A simple demonstration application showing how to create a horizontal 3D bar chart using data
    * from a {@link CategoryDataset}.
    public class BarChart3DDemo2 extends ApplicationFrame {
    // * JFREECHART DEVELOPER GUIDE *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available *
    // * to purchase from Object Refinery Limited: *
    // * Sales are used to provide funding for the JFreeChart project - please *
    // * support us so that we can continue developing free software. *
    * Creates a new demo.
    * @param title the frame title.
    public BarChart3DDemo2(final String title) {
    super(title);
    // create the chart...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(23.0, "Series 1", "London");
    dataset.addValue(11.0, "Series 1", "New York");
    dataset.addValue(12.0, "Series 1", "Istanbul");
    dataset.addValue(13.0, "Series 1", "Cairo");
    dataset.addValue(13.0, "Series 2", "London");
    dataset.addValue(19.0, "Series 2", "New York");
    dataset.addValue(19.0, "Series 2", "Istanbul");
    dataset.addValue(19.0, "Series 2", "Cairo");
    dataset.addValue(7.0, "Series 3", "London");
    dataset.addValue(9.0, "Series 3", "New York");
    dataset.addValue(9.0, "Series 3", "Istanbul");
    dataset.addValue(9.0, "Series 3", "Cairo");
    final JFreeChart chart = createChart(dataset);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
    * Creates a chart.
    * @param dataset the dataset.
    * @return The chart.
    private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBarChart3D(
    "3D Bar Chart Demo 2", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.HORIZONTAL, // orientation
    true, // include legend
    true, // tooltips
    false // urls
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);
    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();
    final CategoryLabelPosition left = new CategoryLabelPosition(
    RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
    TextAnchor.CENTER_LEFT, 0.0,
    CategoryLabelWidthType.RANGE, 0.30f
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));
    return chart;
    public void saveimage()
    Image backbuffer;
    ImageObserver observer=null;
    BufferedImage bufferedImage = new BufferedImage (1000,100,BufferedImage.TYPE_INT_BGR );
    // BufferedImage bufferedImage = new BufferedImage ( 1000,100,BufferedImage.TYPE_INT_RGB );
    //      bufferedImage.createGraphics().drawImage( backbuffer, 0, 0,this);
    bufferedImage.createGraphics().drawImage(bufferedImage, 10, 60,observer);
                   try {
                   ImageIO.write( bufferedImage, "jpg", new File ( "image.jpg" ) );
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
    * Starting point for the demonstration application.
    * @param args ignored.
    public static void main(final String[] args) {
    Log.getInstance().addTarget(new PrintStreamLogTarget());
    final BarChart3DDemo2 demo = new BarChart3DDemo2("3D Bar Chart Demo 2");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.saveimage();
    demo.setVisible(true);
    }

    Hi Pradip, its very simple to save the applet as PNG or JPEG. Firstly u dont have to create a function
    saveimage() as u did. delete it. Instead, in the createchart function after the code --------
    final JFreeChart chart = ChartFactory.createBarChart3D(
    "3D Bar Chart Demo 2", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.HORIZONTAL, // orientation
    true, // include legend
    true, // tooltips
    false // urls
    //append the following code to it
    try {
         ChartUtilities.saveChartAsJPEG(
    new java.io.File("C:/hi.JPEG"), chart, 800, 300);
         } catch (java.io.IOException exc) {
         System.err.println("Error writing image to file");
    //then continue with the rest...BINGO!!! its done...

  • Passing JAVA objects to different methods

    As you can see that
    "public static IntervalCategoryDataset createDataset()" want to get the data and attributes from storeStartDate and storeEndDate methods. i have class files, StartDate and EndDate that contains all the accessor methods. after i have store the relevant attributes, i want to call it out in the "public static IntervalCategoryDataset createDataset()" method to manipulate it.
    i hope that my question doesn't confuse you all. hope that you all can guide me on this. Thank you
    package ericTest;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.text.ParseException;
    import java.util.StringTokenizer;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.Calendar;
    import java.util.Date;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.data.category.IntervalCategoryDataset;
    import org.jfree.data.gantt.Task;
    import org.jfree.data.gantt.TaskSeries;
    import org.jfree.data.gantt.TaskSeriesCollection;
    import org.jfree.data.time.SimpleTimePeriod;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    import Gantt.Chart;
    import com.db4o.Db4o;
    import com.db4o.ObjectContainer;
    import com.db4o.ObjectSet;
    public class GanttDemo3 extends ApplicationFrame {
         private static ObjectContainer db;
         private static String day;
         private static String month;
         private static String year;
         private static String task;
         private static String startDate;
         private static String endDate;
         private static String startDay;
         private static String startMonth;
         private static String startYear;
         public static int startDay1;
         public static int startMonth1;
         public static int startYear1;
         public static int startDay2;
         public static int startMonth2;
         public static int startYear2;
         public static String endDay;
         public static String endMonth;
         public static String endYear;
         public static int endDay1;
         public static int endMonth1;
         public static int endYear1;
         public static int endDay2;
         public static int endMonth2;
         public static int endYear2;
         DataInputStream dis = null;
         String fileRecord = null;
       public GanttDemo3(final String title) {
            super(title);
            final IntervalCategoryDataset dataset = createDataset();
            final JFreeChart chart = createChart(dataset);
            // add the chart to a panel...
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
             public final static String filename = "C:\\KLGCC Mock Up.yap";
             public void storeData() throws IOException{
                  new File(filename).delete();
                  db = Db4o.openFile(filename);
                       File f = new File("C:\\KLGCC Mock Up.txt");
                       FileReader fis = new FileReader(f);
                       BufferedReader bis = new BufferedReader(fis);
                       while((fileRecord = bis.readLine()) != null){
                                 StringTokenizer st = new StringTokenizer(fileRecord,",");
                                 task = st.nextToken();
                                 startDate = st.nextToken();
                                 endDate = st.nextToken();
                                 Country c = new Country(task, startDate, endDate);
                                 db.set(c);               
                       db.close();
             public void storeStartDate() throws ParseException{
                  db = Db4o.openFile(filename);
                  Country c = new Country();
                  ObjectSet result = db.get(c);
                  while(result.hasNext()){
                       Country obj = (Country)result.next();
                       String sDate = obj.getStartDate();
                       StringTokenizer str = new StringTokenizer(sDate, "/");
                       startMonth = str.nextToken();
                       startDay = str.nextToken();
                       startYear = str.nextToken();
                       int startMonth1 = Integer.parseInt(startMonth);
                       int startDay1 = Integer.parseInt(startDay);
                       int startYear1 = Integer.parseInt(startYear);
                       StartDate sd = new StartDate(startDay1, startMonth1, startYear1);
                       ArrayList<Integer> startDay2 = new ArrayList<Integer>();
                       startDay2.add(startDay1);
                       ArrayList<Integer> startMonth2 = new ArrayList<Integer>();
                       startMonth2.add(startMonth1);
                       ArrayList<Integer> startYear2 = new ArrayList<Integer>();
                       startYear2.add(startYear1);                 
                  db.close();          
        public void storeEndDate() throws ParseException{
                  db = Db4o.openFile(filename);
                  Country c = new Country();
                  ObjectSet result = db.get(c);
                  while(result.hasNext()){
                       Country obj = (Country)result.next();
                       String sEndDate = obj.getEndDate();
                       StringTokenizer str1 = new StringTokenizer(sEndDate, "/");
                       endMonth = str1.nextToken();
                       endDay = str1.nextToken();
                       endYear = str1.nextToken();
                       int endMonth1 = Integer.parseInt(endMonth);
                       int endDay1 = Integer.parseInt(endDay);
                       int endYear1 = Integer.parseInt(endYear);
                       EndDate ed = new EndDate(endDay1, endMonth1, endYear1);
                       ArrayList<Integer> endDay2 = new ArrayList<Integer>();
                       endDay2.add(startDay1);
                       ArrayList<Integer> endMonth2 = new ArrayList<Integer>();
                       endMonth2.add(endMonth1);
                       ArrayList<Integer> endYear2 = new ArrayList<Integer>();
                       endYear2.add(endYear1);
                  db.close();
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             StartDate sd = new StartDate(startDay1, startMonth1, startYear1);
             EndDate ed = new EndDate(endDay1, endMonth1, endYear1);
            s1.add(new Task(task,
                   new SimpleTimePeriod(date(sd.getStartDay1(),sd.getStartDay1(), sd.getStartYear1()),
                                        date(ed.getEndDay1(), ed.getEndMonth1(), ed.getendYear1()))));
            System.out.println("dumb");
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
         * Utility method for creating <code>Date</code> objects.
         * @param day  the date.
         * @param month  the month.
         * @param year  the year.
         * @return a date.
        private static Date date(final int startDay2, final int startMonth2, final int startYear2) {
            System.out.println("sdojsodj");
             final Calendar calendar = Calendar.getInstance();
            calendar.set(startYear2, startMonth2, startDay2);
            final Date result = calendar.getTime();
            return result;
         * Creates a chart.
         * @param dataset  the dataset.
         * @return The chart.
        private JFreeChart createChart(final IntervalCategoryDataset dataset) {
            final JFreeChart chart = ChartFactory.createGanttChart(
                "Gantt Chart Demo",  // chart title
                "Task",              // domain axis label
                "Date",              // range axis label
                dataset,             // data
                true,                // include legend
                true,                // tooltips
                false                // urls
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
            return chart;   
        public static void main(final String[] args) throws IOException, ParseException
            final GanttDemo3 demo = new GanttDemo3("Gantt Chart Demo 1");
            demo.storeData();
            demo.storeStartDate();
            //demo.storeEndDate();
            //demo.pack();
            //RefineryUtilities.centerFrameOnScreen(demo);
            //demo.setVisible(true);
    }

    the error that came out in eclipse is
    Exception in thread "main" java.lang.IllegalArgumentException: Null 'description' argument.
         at org.jfree.data.gantt.Task.<init>(Task.java:87)
         at ericTest.GanttDemo3.createDataset(GanttDemo3.java:191)
         at ericTest.GanttDemo3.<init>(GanttDemo3.java:78)
         at ericTest.GanttDemo3.main(GanttDemo3.java:248)and if i replace this
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             StartDate sd = new StartDate(startDay1, startMonth1, startYear1);
             EndDate ed = new EndDate(endDay1, endMonth1, endYear1);
            s1.add(new Task(task,
                   new SimpleTimePeriod(date(sd.getStartDay1(),sd.getStartDay1(), sd.getStartYear1()),
                                        date(ed.getEndDay1(), ed.getEndMonth1(), ed.getendYear1()))));
            System.out.println("dumb");
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
        }with
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             Chart chart = new Chart();
            s1.add(new Task(chart.getTitle(),
                   new SimpleTimePeriod(date(chart.getStartDay(), chart.getStartMonth(), chart.getStartYear()),
                                        date(chart.getEndDay(), chart.getEndMonth(), chart.getEndYear()))));
    System.out.println("dumb");
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
        }the chart class file has all the accessor methods and all the values is hard code. so the graph can be generated. the problem now is if i want to get the values from the StartDate and EndDate methods to get the dates so that i can put it into the createDataset method to add the values needed for the graph.
    can anyone help me on this? thanks alot

Maybe you are looking for

  • Sales order info to 3rd party system

    Hi Gurus, I am working an a requirement for an interface from SAP ECC to External party system, i need to send the sale order information . Customer Sales Orders will be created in SAP manuallly or EDI. The order can be amended provided that the orde

  • ONE LICENCE FOR MULTIPLE COMPUTERS ~ PRODUCT KEYS

    I would like to know how you can get licences to use Acrobat on more than two computers with the one serial number? If that isn't possible, are you able to just purchase serial numbers without having to buy the whole program again? Or if neither of t

  • Connecting Printer to PC and MAC?

    Is there a way I can share a non-network printer between my MAC mini and a PC windows VISTA laptop? I have shared printers in a work situation between two PCs but not sure how the MAC will do the same. Printer choices are HP Office jet J5780 or Epson

  • Photoshop type leading shortcut - text selection

    Hi all I have a text box containing text. I know the shortcut to change the leading - alt + arrow keys To use this shortcut I have to select the text which puts big black blocks through the text and I can't really see the leading. Is there a way to u

  • Workflow is not working

    Hi everybody; I'm teaching in a University and recently was provided to us a server for testing Podcasting lectures. Xserve 2 Ghz PowerPC G5, 1Gb RAM and 232 Gb HD (just 9 GB used), Leopard 10.5.2 OS. Of course we choose the hard way so no assistance