Skip to content
Snippets Groups Projects
Commit 3d0823c5 authored by Tim Molter's avatar Tim Molter
Browse files

working on Date charts

parent c92fe4ce
Branches
No related tags found
No related merge requests found
......@@ -19,15 +19,15 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.TimeZone;
import java.util.Random;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.line.ExampleChart;
import com.xeiam.xchart.style.Series;
import com.xeiam.xchart.style.StyleManager.LegendPosition;
public class DateChart01 implements ExampleChart {
......@@ -44,16 +44,18 @@ public class DateChart01 implements ExampleChart {
// Create Chart
Chart chart = new Chart(800, 600);
Random random = new Random();
// generates linear data
Collection<Date> xData = new ArrayList<Date>();
Collection<Number> yData = new ArrayList<Number>();
DateFormat sdf = new SimpleDateFormat("ss:S");
DateFormat sdf = new SimpleDateFormat("ss.S");
Date date = null;
for (int i = 1; i <= 10; i++) {
for (int i = 1; i <= 14; i++) {
try {
date = sdf.parse("31:" + (100 * i));
date = sdf.parse("31." + (100 * i + random.nextInt(20)));
} catch (ParseException e) {
e.printStackTrace();
}
......@@ -63,10 +65,9 @@ public class DateChart01 implements ExampleChart {
// Customize Chart
chart.setChartTitle("DateChart01");
chart.getStyleManager().setTimezone(TimeZone.getTimeZone("UTC"));
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setLegendVisible(false);
Series series = chart.addDateSeries("value", xData, yData);
System.out.println(Arrays.toString(xData.toArray()));
return chart;
......
/**
* Copyright 2011-2013 Xeiam LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.demo.charts.date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Random;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.line.ExampleChart;
import com.xeiam.xchart.style.Series;
public class DateChart02 implements ExampleChart {
public static void main(String[] args) {
ExampleChart exampleChart = new DateChart02();
Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart();
}
@Override
public Chart getChart() {
// Create Chart
Chart chart = new Chart(800, 600);
// generates linear data
Collection<Date> xData = new ArrayList<Date>();
Collection<Number> yData = new ArrayList<Number>();
Random random = new Random();
DateFormat sdf = new SimpleDateFormat("mm:ss.SSS");
Date date = null;
for (int i = 1; i <= 14; i++) {
try {
date = sdf.parse("23:" + (5 * i + random.nextInt(2)) + "." + random.nextInt(1000));
} catch (ParseException e) {
e.printStackTrace();
}
xData.add(date);
yData.add(Math.random() * i);
}
// Customize Chart
chart.setChartTitle("DateChart02");
chart.getStyleManager().setLegendVisible(false);
Series series = chart.addDateSeries("value", xData, yData);
System.out.println(Arrays.toString(xData.toArray()));
return chart;
}
}
/**
* Copyright 2011-2013 Xeiam LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.demo.charts.date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Random;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.line.ExampleChart;
import com.xeiam.xchart.style.Series;
public class DateChart03 implements ExampleChart {
public static void main(String[] args) {
ExampleChart exampleChart = new DateChart03();
Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart();
}
@Override
public Chart getChart() {
// Create Chart
Chart chart = new Chart(800, 600);
// generates linear data
Collection<Date> xData = new ArrayList<Date>();
Collection<Number> yData = new ArrayList<Number>();
Random random = new Random();
DateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
Date date = null;
for (int i = 1; i <= 14; i++) {
try {
date = sdf.parse("08:" + (5 * i + random.nextInt(2)) + ":" + (random.nextInt(2)) + "." + random.nextInt(1000));
} catch (ParseException e) {
e.printStackTrace();
}
xData.add(date);
yData.add(Math.random() * i);
}
// Customize Chart
chart.setChartTitle("DateChart03");
chart.getStyleManager().setLegendVisible(false);
Series series = chart.addDateSeries("value", xData, yData);
System.out.println(Arrays.toString(xData.toArray()));
return chart;
}
}
......@@ -37,13 +37,13 @@ import com.xeiam.xchart.style.StyleManager;
*/
public class DateAxisTickCalculator extends AxisTickCalculator {
public static final long SEC_SCALE = TimeUnit.SECONDS.toMillis(1L);
public static final long MIN_SCALE = TimeUnit.MINUTES.toMillis(1L);
public static final long HOUR_SCALE = TimeUnit.HOURS.toMillis(1L);
public static final long DAY_SCALE = TimeUnit.DAYS.toMillis(1L);
public static final long WEEK_SCALE = TimeUnit.DAYS.toMillis(1L) * 7;
public static final long MONTH_SCALE = TimeUnit.DAYS.toMillis(1L) * 31;
public static final long YEAR_SCALE = TimeUnit.DAYS.toMillis(1L) * 365;
public static final long SEC_SCALE = TimeUnit.SECONDS.toMillis(2L);
public static final long MIN_SCALE = TimeUnit.MINUTES.toMillis(2L);
public static final long HOUR_SCALE = TimeUnit.HOURS.toMillis(2L);
public static final long DAY_SCALE = TimeUnit.DAYS.toMillis(2L);
public static final long WEEK_SCALE = TimeUnit.DAYS.toMillis(2L) * 7;
public static final long MONTH_SCALE = TimeUnit.DAYS.toMillis(2L) * 31;
public static final long YEAR_SCALE = TimeUnit.DAYS.toMillis(2L) * 365;
/**
* Constructor
......@@ -146,7 +146,7 @@ public class DateAxisTickCalculator extends AxisTickCalculator {
long diff = max.subtract(min).longValue();
if (diff < SEC_SCALE) {
datePattern = "ss:S";
datePattern = "ss.SSS";
} else if (diff < MIN_SCALE) {
datePattern = "mm:ss";
} else if (diff < HOUR_SCALE) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment