Why is the data in a timeseriescollection chart don't appear correctly?


I'm made ​​a chart timeseriescollection type. I'm fetching the following values ​​to the database.

However when creating the graph, the values ​​shown are not entirely accurate. Can someone tell me why this happens?

Only shows the date. Hours not appear correctly. Does anyone can help me solve this little problem please? I would be eternally grateful.

Thank you all very much.

Values from Database.

select (CONCAT(data_registo, ' ', hora_registo)) as data, temperatura from registos where idSensor like 'Thermomether001' and data_registo between '2014-07-20' and '2014-07-24' 2014-07-20 00:26:03 19.4 2014-07-20 00:55:07 18.4 2014-07-20 01:58:14 18.4 2014-07-20 03:03:02 18.4 2014-07-20 04:40:13 19.3 2014-07-20 05:10:56 18.4 2014-07-20 05:41:40 19.3 . . . 2014-07-24 21:40:04 19.3 2014-07-24 22:09:42 19.2 2014-07-24 22:39:20 18.9 2014-07-24 23:02:19 19.8 2014-07-24 23:38:37 19.7


<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/zAyNi.png" data-original="https://i.stack.imgur.com/zAyNi.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

As you can see only shows the date. The time that appears is not registered in the database. Can anyone help me?

Code of chart

JFreeChart createChart(XYDataset dataset) {

JFreeChart chart = ChartFactory.createTimeSeriesChart( "Chart", // title "Date", // x-axis label "Temperature", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); return chart; } XYDataset createDataset() throws SQLException, ParseException { Connection con = null; String databaseURL = "jdbc:sqlserver://-----;IntegratedSecurity=true"; String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; try { Class.forName(driverName).newInstance(); } catch (Exception ex) { System.out.println(""); } con = (Connection) DriverManager.getConnection(databaseURL); if (!con.isClosed()) { System.out.println("Successfully connected to the DataBase Server..."); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d1 = sdf.format(jDateChooser1.getDate()); String d2 = sdf.format(jDateChooser2.getDate()); String c1 = jComboBoxSensores.getSelectedItem().toString(); Statement statement; statement = (Statement) con.createStatement(); String selectQuery ="select (CONCAT(data_registo, ' ', hora_registo)) as data, temperatura from registos where idSensor like '"+c1+"' and temperatura not in ('0.0') and data_registo between '"+d1+"' and '"+d2+"'"; ResultSet resultSet = null; resultSet = statement.executeQuery(selectQuery); TimeSeries s1 = new TimeSeries(c1); while (resultSet.next()) { String data = (String) resultSet.getObject("data"); String temperatura = (String) resultSet.getObject("temperatura"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dateI = sdf2.parse(data); double value = Double.parseDouble(temperatura); s1.addOrUpdate(new Hour(dateI), value); } resultSet.close(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; } JPanel createDemoPanel() throws SQLException, ParseException { JFreeChart chart = createChart(createDataset()); ChartPanel panel = new ChartPanel(chart); panel.setFillZoomRectangle(true); panel.setMouseWheelEnabled(true); return panel; } }

As you can see only shows the date. The time that appears is not registered in the database. Can anyone help me?

Very thanks everyone.


You're truncating dateI to the nearest hour. Instead, use Second to preserve the full resolution retrieved from the query and store the result in the model.

s1.addOrUpdate(new Second(dateI), value);

In the view, you can setDateFormatOverride() to the desired format on the domain axis, as shown <a href="https://stackoverflow.com/search?tab=votes&q=user%3a230513%20%5bjfreechart%5d%20setDateFormatOverride" rel="nofollow">here</a>.

axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd HH"));


  • How to create a new column with names in a list
  • best way to exchange custom XML elements in XMPP?
  • Passing string array to webservice method
  • Legend control with two data frames of different x-scales and different geoms in ggplot2
  • Dynamic DropDownLists In MVC 4 Form
  • R ggvis interactive slider for calculating y values (e.g. for background correction)
  • How to increase the python speed over loops?
  • Plotly and ggplot with facet_grid in R: How to to get yaxis labels to use ticktext value instead of
  • angular2 chart and events
  • Keep same scale in different graphs ggplot2
  • JFreechart X and Y axis scaling
  • Greek letters in legend in R
  • HighCharts - Show tooltip on column where value is 0 or null
  • select function not working in 3.5.4 version of d3.js
  • xcode don't localize specific strings
  • SetWindowsHookEx does not react on media keys
  • Breaking out column by groups in Pandas
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Swift: Switch statement fallthrough behavior
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • Illegal mix of collations for operation for date/time comparison
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Release, debug version and Authorization Google?
  • Adding custom controls to a full screen movie
  • To display the title for the current loaction in map in iphone
  • Comma separated Values
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • trying to dynamically update Highchart column chart but series undefined
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • Why joiner is not used after Sequence generator or Update statergy
  • how does django model after text[] in postgresql [duplicate]
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • Android Heatmap on canvas or ImageView