Setting date range in DynamicTimeSeriesCollection horizontal axis - jfreechart

I am now working on a DynamicTimeSeriesCollection chart which display energy value in Y-axis, and X-axis should be date.
private final Second time = new Second();
private final DynamicTimeSeriesCollection dataset = new DynamicTimeSeriesCollection(1, 180, time);
The JFreeChart display a tick every 1/2 second automatically as the following example!
00:13:00
00:13:30
00:14:00
00:14:30
How can I change them by my customized value as:
00:13:00---> 01-Jan-2011
00:13:30---> 02-Jan-2011
00:14:00---> 03-Jan-2011
00:14:30---> 04-Jan-2011
(1 default second = 2 days in my case).
I can't find any solution, could any one help?

OK. Finally i resolved my question by using TimeSeries. We can create a dataset as we need:
TimeSeries s1 = new TimeSeries("L&G European Index Trust");
s1.add(new Day(1, 1, 2001), 181.8);
s1.add(new Day(3, 1, 2001), 181.8);
s1.add(new Day(5, 1, 2001), 167.3);
s1.add(new Day(7, 1, 2001), 153.8);
In TimeSeries we can control dataset, i means value and date better than DynamicTimeSeriesCollection.

Related

JFreeChart Gantt display subtasks' overlapping

I need to visualize overlapping of subtasks. In my case, a task is one person1, and subtasks of each task have descriptions "SignIn", "SignOut", "Click" (short-duration tasks), "Call" (long-duration task). What I want is to be able to: 1. See the overlap of 2 calls and see overlap of shortTasks and longTasks.
Something similar to this
My thoughts:
Lower the transparency of subtasks, then the overlapping areas will be rendered as darker. (In real life, if there is a green object with alpha 20 overlap or laying on top of a red object with alpha 100, we should see a render of green + red in the overlapped area?)
Render the shortTasks on a overlay above longTasks, so that the short tasks will displayed above the long task. <-- Still haven't figured out how to do this in code
I've followed this Changing saturation of subtasks, changing transparency in getItemPaint
Color rbg = clut.get(clutIndex);
return new Color(rbg.getRed(), rbg.getGreen(), rbg.getBlue(), 150);
but it's not exactly what I'm looking for, since the overlapped areas are not demonstrated.
private #NotNull IntervalCategoryDataset createDataset() {
final TaskSeries s1 = new TaskSeries("Scheduled");
Task person1 = new Task("Person1",
new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
date(30, Calendar.APRIL, 2001)));
// Subtasks
Task subTask1 = new Task("SignIn",
new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
date(2, Calendar.APRIL, 2001))); // no overlap
Task subTask2 = new Task("Call1",
new SimpleTimePeriod(date(5, Calendar.APRIL, 2001),
date(20, Calendar.APRIL, 2001))); // day 5 - 20
Task subTask3 = new Task("Click",
new SimpleTimePeriod(date(16, Calendar.APRIL, 2001),
date(17, Calendar.APRIL, 2001))); // overlap with call1 and call2
Task subTask4 = new Task("Call2",
new SimpleTimePeriod(date(15, Calendar.APRIL, 2001),
date(30, Calendar.APRIL, 2001))); // day 15 - 30
person1.addSubtask(subTask1);
person1.addSubtask(subTask2);
person1.addSubtask(subTask3);
person1.addSubtask(subTask4);
s1.add(person1);
final TaskSeriesCollection collection = new TaskSeriesCollection();
collection.add(s1);
return collection;
}
How to code using my approach or is there any better approaches to achieve this?
Thank you!
While GanttRenderer doesn't support AlphaComposite directly, you can adjust the hue, saturation and brightness; saturation is shown here, but ⍺ < 1 may be worth exploring. You can set the mode in your implementation of drawItem(); Xor is pictured. Use the AlphaCompositeDemo cited here to find the desired mode and colors.
private static class MyRenderer extends GanttRenderer {
…
#Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
g2.setComposite(AlphaComposite.Xor);
super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
}
}

Jfree chart version of jide soft line chart with gradient fill

I need to get the code that would help me create a chart similar to the one shown in the image http://www.jidesoft.com/images/line-chart-gradient-fill.png also it should be a time series chart
First of all I want to recommend to buy the JFreeChart developers guide. It contains a large set of good examples and it supports the maintainer of this project.
Regarding your question: I don't know what your main target is.
A good starting point is the class TimeSeriesChartDemo1 provided with the JFreeChart sources.
Modify the createChart method of this demo by setting a different renderer:
private static JFreeChart createChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Legal & General Unit Trust Prices", // title
"Date", // x-axis label
"Price Per Unit", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
chart.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYItemRenderer r = new XYAreaRenderer2();
r.setSeriesPaint(0, new Color(255, 0, 0, 50));
r.setSeriesPaint(0, new Color(0, 255, 0, 50));
plot.setRenderer(r);
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
return chart;
}

How to add calendar item using MonoDroid?

I'm trying to add an event to a calendar on an android device, and I'm using MonoDroid. I found the following example in Java: http://www.androidcookbook.com/Recipe.seam?recipeId=3852
I tried to translate the first code snippet to C#, but I have trouble setting the "beginTime" and "endTime" fields, especially translating from Calendar.getTimeInMillis() to System.DateTime. This is my code:
DateTime epoch = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan startSpan = fromDate - epoch;
TimeSpan endSpan = toDate - epoch;
Intent intent = new Intent(Intent.ActionEdit);
intent.SetType("vnd.android.cursor.item/event");
intent.PutExtra("beginTime", startSpan.TotalMilliseconds);
intent.PutExtra("endTime", endSpan.TotalMilliseconds);
The result is that the from and to fields are filled with today's date and a time slot with length of one hour.
How do I correctly set begin/end time of the event?
I have used a helper method in the past that has worked out pretty well. Here is a quick sample that should set the date and time properly.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
AddEvent(this, "Sample Event", DateTime.UtcNow, DateTime.UtcNow.AddHours(5));
}
public void AddEvent(Context ctx, String title, DateTime start, DateTime end)
{
var intent = new Intent(Intent.ActionEdit);
intent.SetType("vnd.android.cursor.item/event");
intent.PutExtra("title", title);
intent.PutExtra("beginTime", TimeInMillis(start));
intent.PutExtra("endTime", TimeInMillis(end));
intent.PutExtra("allDay", false);
ctx.StartActivity(intent);
}
private readonly static DateTime jan1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private static Int64 TimeInMillis(DateTime dateTime)
{
return (Int64)(dateTime - jan1970).TotalMilliseconds;
}

JFreeChart : How to make a series invisible?

I am trying to make a chart of ohlc bars invisible so that I can leave the window with only the moving average.
Here is the code with the two series (ohlc bars and moving average) :
private static JFreeChart createChart(OHLCDataset dataset)
{
JFreeChart chart = ChartFactory.createHighLowChart(
"HighLowChartDemo2",
"Time",
"Value",
dataset,
true);
XYPlot plot = (XYPlot)chart.getPlot();
DateAxis axis = (DateAxis)plot.getDomainAxis();
axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
yAxis.setNumberFormatOverride(new DecimalFormat("$0.00"));
//overlay the moving average dataset...
XYDataset dataset2 = MovingAverage.createMovingAverage(dataset, "-MAVG", 3 * 24 * 60 * 60 * 1000L, 0L);
plot.setDataset(1, dataset2);
plot.setRenderer(1, new StandardXYItemRenderer());
XYItemRenderer theRenderer = plot.getRenderer(0);
theRenderer.setSeriesVisible(0, false);
return chart;
}
For some reason setSeriesVisible function is not working.
Any ideas?
Thank you.
HighLowRenderer ignores getSeriesVisible() and getBaseSeriesVisible(), although it does check getDrawOpenTicks() and getDrawCloseTicks(). You can replace the OHLCDataset:
plot.setDataset(0, null);
Alternatively, don't add the OHLCDataset in the first place; just use it to create the MovingAverage.

TimePicker Minimum value Silverlight

I wan't to use a TimePicker but setting to it a minimum posible value, that the user can't choose other after that value.
Like the DisplayDateStart in DatePicker.
You can use Minimum and Maximum properties of TimePicker Control in silverlight to limit the times displayed in drop down menu.
startTime.Maximum = endTime;
endTime.Minimum = startTime;
here startTime and endTime are two timepickers
In datefield using throw the BlackoutDates
MonthlyDatePicker.DisplayDate = new DateTime(2009, 5, 1);
MonthlyDatePicker.DisplayDateStart = new DateTime(2009, 1, 1);
MonthlyDatePicker.DisplayDateEnd = new DateTime(2009, 1, 31);
or
MonthlyDatePicker.BlackoutDates.Add(new DatePickerDateRange(
new DateTime(2009, 1, 1),
new DateTime(2009, 1, 4)
));
i think i hope its helps to you

Resources