Home » Archived » BIRT » Marker lines on date time X axis
Marker lines on date time X axis [message #88742] |
Tue, 08 November 2005 10:12  |
Eclipse User |
|
|
|
Originally posted by: pjpaulin.yahoo.com
I'm trying to create a marker line on a datetime X axis, but the line is
not appearing. I create the X axis with the following code:
AxisImpl xAxisPrimary = (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.DATE_TIME_LITERAL);
xAxisPrimary.setCategoryAxis(true);
Then set the data:
DateTimeDataSet dateTimeValues = DateTimeDataSetImpl.create(new
CDateTime[] { new CDateTime(2005, 1, 1), new CDateTime(2005, 1, 2), new
CDateTime(2005, 1, 3) });
Series dateTimeSeries = SeriesImpl.create();
dateTimeSeries.setDataSet(dateTimeValues);
Then finally, I attempt to create the marker with a CDateTime as the input:
MarkerLineImpl.create(xAxisPrimary, DateTimeDataElementImpl.create(new
CDateTime(2005, 1, 2)));
No marker line appears, however. If I omit setting the axis type to
DATE_TIME_LITERAL, then I can set the marker by passing in the integer
index of the date in the series. But then I lose the ability to format the
date labels below the axis.
Is there something I'm forgetting to do? Thanks for your help.
--- Patrick
|
|
|
Re: Marker lines on date time X axis [message #88999 is a reply to message #88742] |
Tue, 08 November 2005 21:12   |
Eclipse User |
|
|
|
Hi Patrick,
Did you add the MarkerLine into the axis?
E.g. MarkerLine ml = MarkerLineImpl.create(xAxisPrimary,
DateTimeDataElementImpl.create(new CDateTime(2005, 1, 2)));
xAxisPrimary.getMarkerLines( ).add( ml );
Cheers.
Regards,
Nina
"Patrick Paulin" <pjpaulin@yahoo.com> wrote in message
news:ce7200dc64fc401a1f9fbf5c4c215bc9$1@www.eclipse.org...
> I'm trying to create a marker line on a datetime X axis, but the line is
> not appearing. I create the X axis with the following code:
>
> AxisImpl xAxisPrimary = (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
> xAxisPrimary.setType(AxisType.DATE_TIME_LITERAL);
> xAxisPrimary.setCategoryAxis(true);
>
> Then set the data:
>
> DateTimeDataSet dateTimeValues = DateTimeDataSetImpl.create(new
> CDateTime[] { new CDateTime(2005, 1, 1), new CDateTime(2005, 1, 2), new
> CDateTime(2005, 1, 3) });
> Series dateTimeSeries = SeriesImpl.create();
> dateTimeSeries.setDataSet(dateTimeValues);
>
> Then finally, I attempt to create the marker with a CDateTime as the
> input:
>
> MarkerLineImpl.create(xAxisPrimary, DateTimeDataElementImpl.create(new
> CDateTime(2005, 1, 2)));
>
> No marker line appears, however. If I omit setting the axis type to
> DATE_TIME_LITERAL, then I can set the marker by passing in the integer
> index of the date in the series. But then I lose the ability to format the
> date labels below the axis.
> Is there something I'm forgetting to do? Thanks for your help.
>
> --- Patrick
>
>
>
|
|
| |
Re: Marker lines on date time X axis [message #89342 is a reply to message #89327] |
Wed, 09 November 2005 13:52   |
Eclipse User |
|
|
|
Originally posted by: pjpaulin.yahoo.com
Whoops! Forgot the code snippet. Here it is:
package test;
import java.util.Locale;
import org.eclipse.birt.chart.device.IDeviceRenderer;
import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.Generator;
import org.eclipse.birt.chart.factory.RunTimeContext;
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
import org.eclipse.birt.chart.model.component.MarkerLine;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.AxisImpl;
import org.eclipse.birt.chart.model.component.impl.MarkerLineImpl;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.DateTimeDataSet;
import org.eclipse.birt.chart.model.data.NumberDataSet;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.impl.DateTimeDataElementIm pl;
import org.eclipse.birt.chart.model.data.impl.DateTimeDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.chart.util.CDateTime;
import org.eclipse.birt.chart.util.PluginSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.mozilla.javascript.Scriptable;
public class TestDateTimeMarker {
private static final class MyPaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
// let's get a SWT device renderer
IDeviceRenderer deviceRenderer = null;
try {
System.setProperty("STANDALONE", "true");
deviceRenderer = PluginSettings.instance().getDevice("dv.SWT");
} catch (ChartException ex) {
System.err.println("Oops, can't find the device renderer.");
ex.printStackTrace();
System.exit(1);
}
deviceRenderer.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, e.gc);
// now let's make sure we stay in the client area's bounds
Rectangle rect = ((Composite) e.widget).getClientArea();
final Bounds bounds = BoundsImpl.create(rect.x + 2, rect.y + 2,
rect.width - 4, rect.height - 4);
bounds.scale(72d / deviceRenderer.getDisplayServer()
.getDpiResolution());
Chart chart = createChart();
// and finally, generate it...
final Generator gr = Generator.instance();
GeneratedChartState state;
try {
RunTimeContext context = new RunTimeContext();
context.setLocale(Locale.getDefault());
state = gr.build(deviceRenderer.getDisplayServer(), chart,
(Scriptable) null, bounds, context);
gr.render(deviceRenderer, state);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("TestDateTimeMarker");
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.addPaintListener(new MyPaintListener());
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/**
* Creates chart.
*
* @return chart
*/
public static final Chart createChart() {
/* create chart and plot */
ChartWithAxes cwaBar = ChartWithAxesImpl.create();
cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
cwaBar.getBlock().getInsets().set(0, 0, 0, 0);
Plot p = cwaBar.getPlot();
p.getClientArea().setBackground(
ColorDefinitionImpl.create(255, 255, 225));
p.getInsets().set(0, 0, 0, 0);
/* create X axis */
AxisImpl xAxisPrimary = (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.DATE_TIME_LITERAL);
xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
xAxisPrimary.getTitle().setVisible(false);
xAxisPrimary.setCategoryAxis(true);
/* create Y axis */
AxisImpl yAxisPrimary = (AxisImpl) cwaBar
.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getLineAttributes().setVisible(false);
yAxisPrimary.getLabel().getCaption().setColor(
ColorDefinitionImpl.create(80, 80, 80));
yAxisPrimary.getLabel().getCaption().getFont().setSize(10.0f );
yAxisPrimary.getTitle().setVisible(false);
yAxisPrimary.getMajorGrid().getLineAttributes().setColor(
ColorDefinitionImpl.WHITE());
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
/* create date time series and attach to X axis */
DateTimeDataSet dateTimeValues = DateTimeDataSetImpl
.create(new CDateTime[] { new CDateTime(2005, 1, 1),
new CDateTime(2005, 1, 2), new CDateTime(2005, 1, 3) });
Series dateTimeSeries = SeriesImpl.create();
dateTimeSeries.setDataSet(dateTimeValues);
SeriesDefinition xseriesDefinition = SeriesDefinitionImpl.create();
xseriesDefinition.getSeriesPalette().update(0);
xAxisPrimary.getSeriesDefinitions().add(xseriesDefinition);
xseriesDefinition.getSeries().add(dateTimeSeries);
/* set line series and attach to Y axis */
NumberDataSet orthoValues1 = NumberDataSetImpl.create(new Double[] {
new Double(10), new Double(20), new Double(30) });
Series lineSeries = LineSeriesImpl.create();
lineSeries.setDataSet(orthoValues1);
SeriesDefinition yseriesDefinition = SeriesDefinitionImpl.create();
yseriesDefinition.getSeriesPalette().update(1);
yAxisPrimary.getSeriesDefinitions().add(yseriesDefinition);
yseriesDefinition.getSeries().add(lineSeries);
/* add marker to X axis */
MarkerLine markerLine = MarkerLineImpl.create(xAxisPrimary,
DateTimeDataElementImpl.create(new CDateTime(2005, 1, 2)));
xAxisPrimary.getMarkerLines().add(markerLine);
return cwaBar;
}
}
|
|
| |
Goto Forum:
Current Time: Tue May 06 12:03:14 EDT 2025
Powered by FUDForum. Page generated in 0.11374 seconds
|