Home » Archived » BIRT » create a line chart programmatically
|
Re: create a line chart programmatically [message #11953 is a reply to message #11941] |
Fri, 25 February 2005 14:30   |
Eclipse User |
|
|
|
Hi Guy,
I assume you've been successful at building the chart library.
Here's how you could create a sample line chart that relies on the chart
library model (either as source or as JARs in your environment):
/**
* Creates a line chart model as a reference implementation
*
* @return An instance of the simulated runtime chart model
(containing filled datasets)
*/
public static final Chart createSimpleLineChart()
{
ChartWithAxes cwaBar = ChartWithAxesImpl.create();
cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
Plot p = cwaBar.getPlot();
p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
255, 225));
cwaBar.getTitle().getLabel().getCaption().setValue("Sample Line
Chart");
Legend lg = cwaBar.getLegend();
LineAttributes lia = lg.getOutline();
lg.getText().getFont().setSize(16);
lia.setStyle(LineStyle.SOLID_LITERAL);
lg.getInsets().set(10, 5, 0, 0);
lg.getOutline().setVisible(false);
lg.setAnchor(Anchor.NORTH_LITERAL);
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.TEXT_LITERAL);
xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
xAxisPrimary.getTitle().setVisible(false);
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
yAxisPrimary.setPercent(true);
Vector vs = new Vector();
vs.add("one");
vs.add("two");
vs.add("three");
ArrayList vn1 = new ArrayList();
vn1.add(new Double(25));
vn1.add(new Double(35));
vn1.add(new Double(-45));
TextDataSet categoryValues = TextDataSetImpl.create(vs);
NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
// CREATE THE CATEGORY SERIES
Series seCategory = SeriesImpl.create();
seCategory.setDataSet(categoryValues);
// CREATE THE PRIMARY DATASET
LineSeries ls = (LineSeries) LineSeriesImpl.create();
ls.setSeriesIdentifier("My Line Series");
ls.setDataSet(orthoValues1);
ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
ls.getLabel().setVisible(true);
SeriesDefinition sdX = SeriesDefinitionImpl.create();
sdX.getSeriesPalette().update(0); // SET THE COLORS IN THE PALETTE
xAxisPrimary.getSeriesDefinitions().add(sdX);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette().update(1); // SET THE COLORS IN THE PALETTE
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdX.getSeries().add(seCategory);
sdY.getSeries().add(ls);
return cwaBar;
}
Regards,
Rohit Colaco
ECE Project Lead
---------
Guy Nirpaz wrote:
> Hello,
> Can anyone please send an example on how to create a line chart
> programatically.
> Thanks,
> Guy
|
|
|
Re: create a line chart programmatically [message #12120 is a reply to message #11953] |
Wed, 02 March 2005 05:06   |
Eclipse User |
|
|
|
Hello,
I'm trying to show this chart in SWT. Can you please post an example how
to show this chart in SWT.
Thanks
Oliver
Rohit Colaco wrote:
> Hi Guy,
> I assume you've been successful at building the chart library.
> Here's how you could create a sample line chart that relies on the chart
> library model (either as source or as JARs in your environment):
> /**
> * Creates a line chart model as a reference implementation
> *
> * @return An instance of the simulated runtime chart model
> (containing filled datasets)
> */
> public static final Chart createSimpleLineChart()
> {
> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
> Plot p = cwaBar.getPlot();
> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
> 255, 225));
> cwaBar.getTitle().getLabel().getCaption().setValue("Sample Line
> Chart");
> Legend lg = cwaBar.getLegend();
> LineAttributes lia = lg.getOutline();
> lg.getText().getFont().setSize(16);
> lia.setStyle(LineStyle.SOLID_LITERAL);
> lg.getInsets().set(10, 5, 0, 0);
> lg.getOutline().setVisible(false);
> lg.setAnchor(Anchor.NORTH_LITERAL);
> Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];
> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
> xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
> xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
> xAxisPrimary.getTitle().setVisible(false);
> Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
> yAxisPrimary.setPercent(true);
> Vector vs = new Vector();
> vs.add("one");
> vs.add("two");
> vs.add("three");
> ArrayList vn1 = new ArrayList();
> vn1.add(new Double(25));
> vn1.add(new Double(35));
> vn1.add(new Double(-45));
> TextDataSet categoryValues = TextDataSetImpl.create(vs);
> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
> // CREATE THE CATEGORY SERIES
> Series seCategory = SeriesImpl.create();
> seCategory.setDataSet(categoryValues);
> // CREATE THE PRIMARY DATASET
> LineSeries ls = (LineSeries) LineSeriesImpl.create();
> ls.setSeriesIdentifier("My Line Series");
> ls.setDataSet(orthoValues1);
> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
> ls.getLabel().setVisible(true);
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> sdX.getSeriesPalette().update(0); // SET THE COLORS IN THE PALETTE
> xAxisPrimary.getSeriesDefinitions().add(sdX);
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> sdY.getSeriesPalette().update(1); // SET THE COLORS IN THE PALETTE
> yAxisPrimary.getSeriesDefinitions().add(sdY);
> sdX.getSeries().add(seCategory);
> sdY.getSeries().add(ls);
> return cwaBar;
> }
> Regards,
> Rohit Colaco
> ECE Project Lead
> ---------
> Guy Nirpaz wrote:
>> Hello,
>> Can anyone please send an example on how to create a line chart
>> programatically.
>> Thanks,
>> Guy
|
|
|
Re: create a line chart programmatically [message #12133 is a reply to message #12120] |
Wed, 02 March 2005 08:10   |
Eclipse User |
|
|
|
Oliver Nautsch a écrit :
> I'm trying to show this chart in SWT. Can you please post an example how
> to show this chart in SWT.
Hi there,
Here's the program I've written using Rohit's code (slightly modified,
as the Axis interface does not contain the getSeriesDefinitions() method
but AxisImpl does). I've adapted the code from the
org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
Hope this helps,
FX.
public class TestLineChart
{
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 (PluginException 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());
// create Rohit's chart
Chart chart = createSimpleLineChart();
// and finally, generate it...
final Generator gr = Generator.instance();
GeneratedChartState state;
try
{
state = gr.build(deviceRenderer.getDisplayServer(),
chart,
(Scriptable) null,
bounds,
Locale.getDefault());
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("TestLineChart");
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 a line chart model as a reference implementation *
*
* @return An instance of the simulated runtime chart model
* (containing filled datasets)
*/
public static final Chart createSimpleLineChart()
{
ChartWithAxes cwaBar = ChartWithAxesImpl.create();
cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
Plot p = cwaBar.getPlot();
p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
255,
225));
cwaBar.getTitle().getLabel().getCaption()
.setValue("Sample Line Chart");
Legend lg = cwaBar.getLegend();
LineAttributes lia = lg.getOutline();
lg.getText().getFont().setSize(16);
lia.setStyle(LineStyle.SOLID_LITERAL);
lg.getInsets().set(10, 5, 0, 0);
lg.getOutline().setVisible(false);
lg.setAnchor(Anchor.NORTH_LITERAL);
AxisImpl xAxisPrimary =
(AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.TEXT_LITERAL);
xAxisPrimary.getMajorGrid()
.setTickStyle(TickStyle.BELOW_LITERAL);
xAxisPrimary.getOrigin()
.setType(IntersectionType.VALUE_LITERAL);
xAxisPrimary.getTitle().setVisible(false);
AxisImpl yAxisPrimary = (AxisImpl) cwaBar
.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getMajorGrid()
.setTickStyle(TickStyle.LEFT_LITERAL);
yAxisPrimary.setPercent(true);
Vector vs = new Vector();
vs.add("one");
vs.add("two");
vs.add("three");
ArrayList vn1 = new ArrayList();
vn1.add(new Double(25));
vn1.add(new Double(35));
vn1.add(new Double(-45));
TextDataSet categoryValues = TextDataSetImpl.create(vs);
NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
// CREATE THE CATEGORY SERIES
Series seCategory = SeriesImpl.create();
seCategory.setDataSet(categoryValues);
// CREATE THE PRIMARY DATASET
LineSeries ls = (LineSeries) LineSeriesImpl.create();
ls.setSeriesIdentifier("My Line Series");
ls.setDataSet(orthoValues1);
ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
ls.getLabel().setVisible(true);
SeriesDefinition sdX = SeriesDefinitionImpl.create();
sdX.getSeriesPalette().update(0);
xAxisPrimary.getSeriesDefinitions().add(sdX);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette().update(1);
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdX.getSeries().add(seCategory);
sdY.getSeries().add(ls);
return cwaBar;
}
}
|
|
|
Re: create a line chart programmatically [message #12145 is a reply to message #12133] |
Wed, 02 March 2005 13:32   |
Eclipse User |
|
|
|
Hi François-Xavier,
Thank you for providing the example on rendering the line chart on an SWT
canvas.
Here's a suggestion on optimizing the number of calls you make to re-build
the chart:
Instead of building and rendering the chart in the paintControl(...)
method, you could choose to build it offscreen and render it any number of
times without re-building it. There is no requirement that a UI component
needs to be showing to be able to build a chart. Hence it is not mandatory
to build the chart in the paintControl(
) method. However, if you choose
to resize the client area, then you'd want to rebuild it for the new
dimensions before you render the chart. So, in effect, you would want to
compute the line chart offscreen when the client area is resized ONLY
rather than for every paint notification. Remember ... the bounds
(specified in points) with which you render the chart must equate to the
bounds used in building the chart.
Also, I looked into the 'org.eclipse.birt.chart.model.component.Axis'
interface and it does contain the 'EList getSeriesDefinitions()' method
declaration.
Rohit Colaco
ECE Project Lead
---
François-Xavier Le Louarn wrote:
> Oliver Nautsch a écrit :
>> I'm trying to show this chart in SWT. Can you please post an example how
>> to show this chart in SWT.
> Hi there,
> Here's the program I've written using Rohit's code (slightly modified,
> as the Axis interface does not contain the getSeriesDefinitions() method
> but AxisImpl does). I've adapted the code from the
> org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
> Hope this helps,
> FX.
> public class TestLineChart
> {
> 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 (PluginException 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());
> // create Rohit's chart
> Chart chart = createSimpleLineChart();
> // and finally, generate it...
> final Generator gr = Generator.instance();
> GeneratedChartState state;
> try
> {
> state = gr.build(deviceRenderer.getDisplayServer(),
> chart,
> (Scriptable) null,
> bounds,
> Locale.getDefault());
> 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("TestLineChart");
> 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 a line chart model as a reference implementation *
> *
> * @return An instance of the simulated runtime chart model
> * (containing filled datasets)
> */
> public static final Chart createSimpleLineChart()
> {
> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
> Plot p = cwaBar.getPlot();
> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
> 255,
> 225));
> cwaBar.getTitle().getLabel().getCaption()
> .setValue("Sample Line Chart");
> Legend lg = cwaBar.getLegend();
> LineAttributes lia = lg.getOutline();
> lg.getText().getFont().setSize(16);
> lia.setStyle(LineStyle.SOLID_LITERAL);
> lg.getInsets().set(10, 5, 0, 0);
> lg.getOutline().setVisible(false);
> lg.setAnchor(Anchor.NORTH_LITERAL);
> AxisImpl xAxisPrimary =
> (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
> xAxisPrimary.getMajorGrid()
> .setTickStyle(TickStyle.BELOW_LITERAL);
> xAxisPrimary.getOrigin()
> .setType(IntersectionType.VALUE_LITERAL);
> xAxisPrimary.getTitle().setVisible(false);
> AxisImpl yAxisPrimary = (AxisImpl) cwaBar
> .getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getMajorGrid()
> .setTickStyle(TickStyle.LEFT_LITERAL);
> yAxisPrimary.setPercent(true);
> Vector vs = new Vector();
> vs.add("one");
> vs.add("two");
> vs.add("three");
> ArrayList vn1 = new ArrayList();
> vn1.add(new Double(25));
> vn1.add(new Double(35));
> vn1.add(new Double(-45));
> TextDataSet categoryValues = TextDataSetImpl.create(vs);
> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
> // CREATE THE CATEGORY SERIES
> Series seCategory = SeriesImpl.create();
> seCategory.setDataSet(categoryValues);
> // CREATE THE PRIMARY DATASET
> LineSeries ls = (LineSeries) LineSeriesImpl.create();
> ls.setSeriesIdentifier("My Line Series");
> ls.setDataSet(orthoValues1);
> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
> ls.getLabel().setVisible(true);
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> sdX.getSeriesPalette().update(0);
> xAxisPrimary.getSeriesDefinitions().add(sdX);
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> sdY.getSeriesPalette().update(1);
> yAxisPrimary.getSeriesDefinitions().add(sdY);
> sdX.getSeries().add(seCategory);
> sdY.getSeries().add(ls);
> return cwaBar;
> }
> }
|
|
| |
Re: create a line chart programmatically [message #12168 is a reply to message #12145] |
Wed, 02 March 2005 15:10   |
Eclipse User |
|
|
|
Thanks François-Xavier, Thanks Rohit,
It works!
I added the following lines and now the build process is offscreen
...
public class TestLineChart {
private static final class MyPaintListener implements PaintListener {
private Chart myChart;
public MyPaintListener(Chart chart) {
this.myChart = chart;
}
...
canvas.addPaintListener(new MyPaintListener(createSimpleLineChart()));
...
Regards
Oliver
Rohit Colaço wrote:
> Hi François-Xavier,
> Thank you for providing the example on rendering the line chart on an SWT
> canvas.
> Here's a suggestion on optimizing the number of calls you make to re-build
> the chart:
> Instead of building and rendering the chart in the paintControl(...)
> method, you could choose to build it offscreen and render it any number of
> times without re-building it. There is no requirement that a UI component
> needs to be showing to be able to build a chart. Hence it is not mandatory
> to build the chart in the paintControl(
) method. However, if you choose
> to resize the client area, then you'd want to rebuild it for the new
> dimensions before you render the chart. So, in effect, you would want to
> compute the line chart offscreen when the client area is resized ONLY
> rather than for every paint notification. Remember ... the bounds
> (specified in points) with which you render the chart must equate to the
> bounds used in building the chart.
> Also, I looked into the 'org.eclipse.birt.chart.model.component.Axis'
> interface and it does contain the 'EList getSeriesDefinitions()' method
> declaration.
> Rohit Colaco
> ECE Project Lead
> ---
> François-Xavier Le Louarn wrote:
>> Oliver Nautsch a écrit :
>>> I'm trying to show this chart in SWT. Can you please post an example how
>>> to show this chart in SWT.
>> Hi there,
>> Here's the program I've written using Rohit's code (slightly modified,
>> as the Axis interface does not contain the getSeriesDefinitions() method
>> but AxisImpl does). I've adapted the code from the
>> org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
>> Hope this helps,
>> FX.
>> public class TestLineChart
>> {
>> 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 (PluginException 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());
>> // create Rohit's chart
>> Chart chart = createSimpleLineChart();
>> // and finally, generate it...
>> final Generator gr = Generator.instance();
>> GeneratedChartState state;
>> try
>> {
>> state = gr.build(deviceRenderer.getDisplayServer(),
>> chart,
>> (Scriptable) null,
>> bounds,
>> Locale.getDefault());
>> 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("TestLineChart");
>> 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 a line chart model as a reference implementation *
>> *
>> * @return An instance of the simulated runtime chart model
>> * (containing filled datasets)
>> */
>> public static final Chart createSimpleLineChart()
>> {
>> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>> Plot p = cwaBar.getPlot();
>> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
>> 255,
>> 225));
>> cwaBar.getTitle().getLabel().getCaption()
>> .setValue("Sample Line Chart");
>> Legend lg = cwaBar.getLegend();
>> LineAttributes lia = lg.getOutline();
>> lg.getText().getFont().setSize(16);
>> lia.setStyle(LineStyle.SOLID_LITERAL);
>> lg.getInsets().set(10, 5, 0, 0);
>> lg.getOutline().setVisible(false);
>> lg.setAnchor(Anchor.NORTH_LITERAL);
>> AxisImpl xAxisPrimary =
>> (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
>> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
>> xAxisPrimary.getMajorGrid()
>> .setTickStyle(TickStyle.BELOW_LITERAL);
>> xAxisPrimary.getOrigin()
>> .setType(IntersectionType.VALUE_LITERAL);
>> xAxisPrimary.getTitle().setVisible(false);
>> AxisImpl yAxisPrimary = (AxisImpl) cwaBar
>> .getPrimaryOrthogonalAxis(xAxisPrimary);
>> yAxisPrimary.getMajorGrid()
>> .setTickStyle(TickStyle.LEFT_LITERAL);
>> yAxisPrimary.setPercent(true);
>> Vector vs = new Vector();
>> vs.add("one");
>> vs.add("two");
>> vs.add("three");
>> ArrayList vn1 = new ArrayList();
>> vn1.add(new Double(25));
>> vn1.add(new Double(35));
>> vn1.add(new Double(-45));
>> TextDataSet categoryValues = TextDataSetImpl.create(vs);
>> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
>> // CREATE THE CATEGORY SERIES
>> Series seCategory = SeriesImpl.create();
>> seCategory.setDataSet(categoryValues);
>> // CREATE THE PRIMARY DATASET
>> LineSeries ls = (LineSeries) LineSeriesImpl.create();
>> ls.setSeriesIdentifier("My Line Series");
>> ls.setDataSet(orthoValues1);
>> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
>> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
>> ls.getLabel().setVisible(true);
>> SeriesDefinition sdX = SeriesDefinitionImpl.create();
>> sdX.getSeriesPalette().update(0);
>> xAxisPrimary.getSeriesDefinitions().add(sdX);
>> SeriesDefinition sdY = SeriesDefinitionImpl.create();
>> sdY.getSeriesPalette().update(1);
>> yAxisPrimary.getSeriesDefinitions().add(sdY);
>> sdX.getSeries().add(seCategory);
>> sdY.getSeries().add(ls);
>> return cwaBar;
>> }
>> }
|
|
|
Re: create a line chart programmatically [message #13025 is a reply to message #12145] |
Thu, 03 March 2005 05:31   |
Eclipse User |
|
|
|
Thanks for the example and hints.
It works!
Oliver
Rohit Colaço wrote:
> Hi François-Xavier,
> Thank you for providing the example on rendering the line chart on an SWT
> canvas.
> Here's a suggestion on optimizing the number of calls you make to re-build
> the chart:
> Instead of building and rendering the chart in the paintControl(...)
> method, you could choose to build it offscreen and render it any number of
> times without re-building it. There is no requirement that a UI component
> needs to be showing to be able to build a chart. Hence it is not mandatory
> to build the chart in the paintControl(
) method. However, if you choose
> to resize the client area, then you'd want to rebuild it for the new
> dimensions before you render the chart. So, in effect, you would want to
> compute the line chart offscreen when the client area is resized ONLY
> rather than for every paint notification. Remember ... the bounds
> (specified in points) with which you render the chart must equate to the
> bounds used in building the chart.
> Also, I looked into the 'org.eclipse.birt.chart.model.component.Axis'
> interface and it does contain the 'EList getSeriesDefinitions()' method
> declaration.
> Rohit Colaco
> ECE Project Lead
> ---
> François-Xavier Le Louarn wrote:
>> Oliver Nautsch a écrit :
>>> I'm trying to show this chart in SWT. Can you please post an example how
>>> to show this chart in SWT.
>> Hi there,
>> Here's the program I've written using Rohit's code (slightly modified,
>> as the Axis interface does not contain the getSeriesDefinitions() method
>> but AxisImpl does). I've adapted the code from the
>> org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
>> Hope this helps,
>> FX.
>> public class TestLineChart
>> {
>> 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 (PluginException 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());
>> // create Rohit's chart
>> Chart chart = createSimpleLineChart();
>> // and finally, generate it...
>> final Generator gr = Generator.instance();
>> GeneratedChartState state;
>> try
>> {
>> state = gr.build(deviceRenderer.getDisplayServer(),
>> chart,
>> (Scriptable) null,
>> bounds,
>> Locale.getDefault());
>> 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("TestLineChart");
>> 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 a line chart model as a reference implementation *
>> *
>> * @return An instance of the simulated runtime chart model
>> * (containing filled datasets)
>> */
>> public static final Chart createSimpleLineChart()
>> {
>> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>> Plot p = cwaBar.getPlot();
>> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
>> 255,
>> 225));
>> cwaBar.getTitle().getLabel().getCaption()
>> .setValue("Sample Line Chart");
>> Legend lg = cwaBar.getLegend();
>> LineAttributes lia = lg.getOutline();
>> lg.getText().getFont().setSize(16);
>> lia.setStyle(LineStyle.SOLID_LITERAL);
>> lg.getInsets().set(10, 5, 0, 0);
>> lg.getOutline().setVisible(false);
>> lg.setAnchor(Anchor.NORTH_LITERAL);
>> AxisImpl xAxisPrimary =
>> (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
>> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
>> xAxisPrimary.getMajorGrid()
>> .setTickStyle(TickStyle.BELOW_LITERAL);
>> xAxisPrimary.getOrigin()
>> .setType(IntersectionType.VALUE_LITERAL);
>> xAxisPrimary.getTitle().setVisible(false);
>> AxisImpl yAxisPrimary = (AxisImpl) cwaBar
>> .getPrimaryOrthogonalAxis(xAxisPrimary);
>> yAxisPrimary.getMajorGrid()
>> .setTickStyle(TickStyle.LEFT_LITERAL);
>> yAxisPrimary.setPercent(true);
>> Vector vs = new Vector();
>> vs.add("one");
>> vs.add("two");
>> vs.add("three");
>> ArrayList vn1 = new ArrayList();
>> vn1.add(new Double(25));
>> vn1.add(new Double(35));
>> vn1.add(new Double(-45));
>> TextDataSet categoryValues = TextDataSetImpl.create(vs);
>> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
>> // CREATE THE CATEGORY SERIES
>> Series seCategory = SeriesImpl.create();
>> seCategory.setDataSet(categoryValues);
>> // CREATE THE PRIMARY DATASET
>> LineSeries ls = (LineSeries) LineSeriesImpl.create();
>> ls.setSeriesIdentifier("My Line Series");
>> ls.setDataSet(orthoValues1);
>> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
>> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
>> ls.getLabel().setVisible(true);
>> SeriesDefinition sdX = SeriesDefinitionImpl.create();
>> sdX.getSeriesPalette().update(0);
>> xAxisPrimary.getSeriesDefinitions().add(sdX);
>> SeriesDefinition sdY = SeriesDefinitionImpl.create();
>> sdY.getSeriesPalette().update(1);
>> yAxisPrimary.getSeriesDefinitions().add(sdY);
>> sdX.getSeries().add(seCategory);
>> sdY.getSeries().add(ls);
>> return cwaBar;
>> }
>> }
|
|
|
Re: create a line chart programmatically [message #17732 is a reply to message #13025] |
Sat, 12 March 2005 13:11   |
Eclipse User |
|
|
|
Originally posted by: jclang.web.de
Hi,
could you make the complete source code of this example available for
download or email it to me? I encountered several problems when trying to
compile the code.
Thank you in advance,
Christian
Oliver Nautsch wrote:
> Thanks for the example and hints.
> It works!
> Oliver
> Rohit Colaço wrote:
>> Hi François-Xavier,
>> Thank you for providing the example on rendering the line chart on an SWT
>> canvas.
>> Here's a suggestion on optimizing the number of calls you make to re-build
>> the chart:
>> Instead of building and rendering the chart in the paintControl(...)
>> method, you could choose to build it offscreen and render it any number of
>> times without re-building it. There is no requirement that a UI component
>> needs to be showing to be able to build a chart. Hence it is not mandatory
>> to build the chart in the paintControl(…) method. However, if you
choose
>> to resize the client area, then you'd want to rebuild it for the new
>> dimensions before you render the chart. So, in effect, you would want to
>> compute the line chart offscreen when the client area is resized ONLY
>> rather than for every paint notification. Remember ... the bounds
>> (specified in points) with which you render the chart must equate to the
>> bounds used in building the chart.
>> Also, I looked into the 'org.eclipse.birt.chart.model.component.Axis'
>> interface and it does contain the 'EList getSeriesDefinitions()' method
>> declaration.
>> Rohit Colaco
>> ECE Project Lead
>> ---
>> François-Xavier Le Louarn wrote:
>>> Oliver Nautsch a écrit :
>>>> I'm trying to show this chart in SWT. Can you please post an example how
>>>> to show this chart in SWT.
>>> Hi there,
>>> Here's the program I've written using Rohit's code (slightly modified,
>>> as the Axis interface does not contain the getSeriesDefinitions() method
>>> but AxisImpl does). I've adapted the code from the
>>> org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
>>> Hope this helps,
>>> FX.
>>> public class TestLineChart
>>> {
>>> 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 (PluginException 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());
>>> // create Rohit's chart
>>> Chart chart = createSimpleLineChart();
>>> // and finally, generate it...
>>> final Generator gr = Generator.instance();
>>> GeneratedChartState state;
>>> try
>>> {
>>> state = gr.build(deviceRenderer.getDisplayServer(),
>>> chart,
>>> (Scriptable) null,
>>> bounds,
>>> Locale.getDefault());
>>> 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("TestLineChart");
>>> 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 a line chart model as a reference implementation *
>>> *
>>> * @return An instance of the simulated runtime chart model
>>> * (containing filled datasets)
>>> */
>>> public static final Chart createSimpleLineChart()
>>> {
>>> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>>> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>>> Plot p = cwaBar.getPlot();
>>> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
>>> 255,
>>> 225));
>>> cwaBar.getTitle().getLabel().getCaption()
>>> .setValue("Sample Line Chart");
>>> Legend lg = cwaBar.getLegend();
>>> LineAttributes lia = lg.getOutline();
>>> lg.getText().getFont().setSize(16);
>>> lia.setStyle(LineStyle.SOLID_LITERAL);
>>> lg.getInsets().set(10, 5, 0, 0);
>>> lg.getOutline().setVisible(false);
>>> lg.setAnchor(Anchor.NORTH_LITERAL);
>>> AxisImpl xAxisPrimary =
>>> (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
>>> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
>>> xAxisPrimary.getMajorGrid()
>>> .setTickStyle(TickStyle.BELOW_LITERAL);
>>> xAxisPrimary.getOrigin()
>>> .setType(IntersectionType.VALUE_LITERAL);
>>> xAxisPrimary.getTitle().setVisible(false);
>>> AxisImpl yAxisPrimary = (AxisImpl) cwaBar
>>> .getPrimaryOrthogonalAxis(xAxisPrimary);
>>> yAxisPrimary.getMajorGrid()
>>> .setTickStyle(TickStyle.LEFT_LITERAL);
>>> yAxisPrimary.setPercent(true);
>>> Vector vs = new Vector();
>>> vs.add("one");
>>> vs.add("two");
>>> vs.add("three");
>>> ArrayList vn1 = new ArrayList();
>>> vn1.add(new Double(25));
>>> vn1.add(new Double(35));
>>> vn1.add(new Double(-45));
>>> TextDataSet categoryValues = TextDataSetImpl.create(vs);
>>> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
>>> // CREATE THE CATEGORY SERIES
>>> Series seCategory = SeriesImpl.create();
>>> seCategory.setDataSet(categoryValues);
>>> // CREATE THE PRIMARY DATASET
>>> LineSeries ls = (LineSeries) LineSeriesImpl.create();
>>> ls.setSeriesIdentifier("My Line Series");
>>> ls.setDataSet(orthoValues1);
>>> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
>>> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
>>> ls.getLabel().setVisible(true);
>>> SeriesDefinition sdX = SeriesDefinitionImpl.create();
>>> sdX.getSeriesPalette().update(0);
>>> xAxisPrimary.getSeriesDefinitions().add(sdX);
>>> SeriesDefinition sdY = SeriesDefinitionImpl.create();
>>> sdY.getSeriesPalette().update(1);
>>> yAxisPrimary.getSeriesDefinitions().add(sdY);
>>> sdX.getSeries().add(seCategory);
>>> sdY.getSeries().add(ls);
>>> return cwaBar;
>>> }
>>> }
|
|
|
Re: create a line chart programmatically [message #18504 is a reply to message #17732] |
Mon, 14 March 2005 17:00   |
Eclipse User |
|
|
|
Hi Christian,
You've got mail with source code illustrating how a sample chart may be
rendered on an SWT or SWING graphics context using a BIRT chart definition.
Rohit Colaco
ECE Project Lead
---
Christian Lang wrote:
> Hi,
> could you make the complete source code of this example available for
> download or email it to me? I encountered several problems when trying to
> compile the code.
> Thank you in advance,
> Christian
> Oliver Nautsch wrote:
>> Thanks for the example and hints.
>> It works!
>> Oliver
>> Rohit Colaço wrote:
>>> Hi François-Xavier,
>>> Thank you for providing the example on rendering the line chart on an SWT
>>> canvas.
>>> Here's a suggestion on optimizing the number of calls you make to re-build
>>> the chart:
>>> Instead of building and rendering the chart in the paintControl(...)
>>> method, you could choose to build it offscreen and render it any number of
>>> times without re-building it. There is no requirement that a UI component
>>> needs to be showing to be able to build a chart. Hence it is not mandatory
>>> to build the chart in the paintControl(
) method. However, if you
> choose
>>> to resize the client area, then you'd want to rebuild it for the new
>>> dimensions before you render the chart. So, in effect, you would want to
>>> compute the line chart offscreen when the client area is resized ONLY
>>> rather than for every paint notification. Remember ... the bounds
>>> (specified in points) with which you render the chart must equate to the
>>> bounds used in building the chart.
>>> Also, I looked into the 'org.eclipse.birt.chart.model.component.Axis'
>>> interface and it does contain the 'EList getSeriesDefinitions()' method
>>> declaration.
>>> Rohit Colaco
>>> ECE Project Lead
>>> ---
>>> François-Xavier Le Louarn wrote:
>>>> Oliver Nautsch a écrit :
>>>>> I'm trying to show this chart in SWT. Can you please post an example how
>>>>> to show this chart in SWT.
>>>> Hi there,
>>>> Here's the program I've written using Rohit's code (slightly modified,
>>>> as the Axis interface does not contain the getSeriesDefinitions() method
>>>> but AxisImpl does). I've adapted the code from the
>>>> org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
>>>> Hope this helps,
>>>> FX.
>>>> public class TestLineChart
>>>> {
>>>> 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 (PluginException 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());
>>>> // create Rohit's chart
>>>> Chart chart = createSimpleLineChart();
>>>> // and finally, generate it...
>>>> final Generator gr = Generator.instance();
>>>> GeneratedChartState state;
>>>> try
>>>> {
>>>> state = gr.build(deviceRenderer.getDisplayServer(),
>>>> chart,
>>>> (Scriptable) null,
>>>> bounds,
>>>> Locale.getDefault());
>>>> 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("TestLineChart");
>>>> 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 a line chart model as a reference implementation *
>>>> *
>>>> * @return An instance of the simulated runtime chart model
>>>> * (containing filled datasets)
>>>> */
>>>> public static final Chart createSimpleLineChart()
>>>> {
>>>> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>>>> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>>>> Plot p = cwaBar.getPlot();
>>>> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
>>>> 255,
>>>> 225));
>>>> cwaBar.getTitle().getLabel().getCaption()
>>>> .setValue("Sample Line Chart");
>>>> Legend lg = cwaBar.getLegend();
>>>> LineAttributes lia = lg.getOutline();
>>>> lg.getText().getFont().setSize(16);
>>>> lia.setStyle(LineStyle.SOLID_LITERAL);
>>>> lg.getInsets().set(10, 5, 0, 0);
>>>> lg.getOutline().setVisible(false);
>>>> lg.setAnchor(Anchor.NORTH_LITERAL);
>>>> AxisImpl xAxisPrimary =
>>>> (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
>>>> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
>>>> xAxisPrimary.getMajorGrid()
>>>> .setTickStyle(TickStyle.BELOW_LITERAL);
>>>> xAxisPrimary.getOrigin()
>>>> .setType(IntersectionType.VALUE_LITERAL);
>>>> xAxisPrimary.getTitle().setVisible(false);
>>>> AxisImpl yAxisPrimary = (AxisImpl) cwaBar
>>>> .getPrimaryOrthogonalAxis(xAxisPrimary);
>>>> yAxisPrimary.getMajorGrid()
>>>> .setTickStyle(TickStyle.LEFT_LITERAL);
>>>> yAxisPrimary.setPercent(true);
>>>> Vector vs = new Vector();
>>>> vs.add("one");
>>>> vs.add("two");
>>>> vs.add("three");
>>>> ArrayList vn1 = new ArrayList();
>>>> vn1.add(new Double(25));
>>>> vn1.add(new Double(35));
>>>> vn1.add(new Double(-45));
>>>> TextDataSet categoryValues = TextDataSetImpl.create(vs);
>>>> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
>>>> // CREATE THE CATEGORY SERIES
>>>> Series seCategory = SeriesImpl.create();
>>>> seCategory.setDataSet(categoryValues);
>>>> // CREATE THE PRIMARY DATASET
>>>> LineSeries ls = (LineSeries) LineSeriesImpl.create();
>>>> ls.setSeriesIdentifier("My Line Series");
>>>> ls.setDataSet(orthoValues1);
>>>> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
>>>> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
>>>> ls.getLabel().setVisible(true);
>>>> SeriesDefinition sdX = SeriesDefinitionImpl.create();
>>>> sdX.getSeriesPalette().update(0);
>>>> xAxisPrimary.getSeriesDefinitions().add(sdX);
>>>> SeriesDefinition sdY = SeriesDefinitionImpl.create();
>>>> sdY.getSeriesPalette().update(1);
>>>> yAxisPrimary.getSeriesDefinitions().add(sdY);
>>>> sdX.getSeries().add(seCategory);
>>>> sdY.getSeries().add(ls);
>>>> return cwaBar;
>>>> }
>>>> }
|
|
|
Re: create a line chart programmatically [message #152126 is a reply to message #13025] |
Sat, 08 April 2006 12:47  |
Eclipse User |
|
|
|
Originally posted by: hth_999.yahoo.com
I found this error while compiling the example, do you have any idea/
Compiling 54 source files to C:\Eclipse\workspace\wisecheck_alpha\classes
[javac]
C:\Eclipse\workspace\wisecheck_alpha\src\com\wisecheck\util\ TestLineChart.java:117:
cannot find symbol
[javac] symbol : method
build(org.eclipse.birt.chart.device.IDisplayServer,org.eclip se.birt.chart.model.Chart,org.mozilla.javascript.Scriptable, org.eclipse.birt.chart.model.attribute.Bounds,java.util.Loca le)
[javac] location: class org.eclipse.birt.chart.factory.Generator
[javac] state = gr.build(deviceRenderer.getDisplayServer(),
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
Oliver Nautsch wrote:
> Thanks for the example and hints.
> It works!
> Oliver
>
> Rohit Colaço wrote:
>
>
>> Hi François-Xavier,
>
>> Thank you for providing the example on rendering the line chart on an
>> SWT canvas.
>
>> Here's a suggestion on optimizing the number of calls you make to
>> re-build the chart:
>
>> Instead of building and rendering the chart in the paintControl(...)
>> method, you could choose to build it offscreen and render it any
>> number of times without re-building it. There is no requirement that a
>> UI component needs to be showing to be able to build a chart. Hence it
>> is not mandatory to build the chart in the paintControl(�) method.
>> However, if you choose to resize the client area, then you'd want to
>> rebuild it for the new dimensions before you render the chart. So, in
>> effect, you would want to compute the line chart offscreen when the
>> client area is resized ONLY rather than for every paint notification.
>> Remember ... the bounds (specified in points) with which you render
>> the chart must equate to the bounds used in building the chart.
>
>> Also, I looked into the 'org.eclipse.birt.chart.model.component.Axis'
>> interface and it does contain the 'EList getSeriesDefinitions()'
>> method declaration.
>
>
>> Rohit Colaco
>> ECE Project Lead
>
>> ---
>
>
>> François-Xavier Le Louarn wrote:
>
>>> Oliver Nautsch a écrit :
>>>> I'm trying to show this chart in SWT. Can you please post an example
>>>> how to show this chart in SWT.
>
>>> Hi there,
>
>>> Here's the program I've written using Rohit's code (slightly
>>> modified, as the Axis interface does not contain the
>>> getSeriesDefinitions() method but AxisImpl does). I've adapted the
>>> code from the org.eclipse.birt.chart.ui.swt.ChartModelAdapter object.
>
>>> Hope this helps,
>>> FX.
>
>
>>> public class TestLineChart
>>> {
>>> 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 (PluginException 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());
>
>>> // create Rohit's chart
>>> Chart chart = createSimpleLineChart();
>
>>> // and finally, generate it...
>>> final Generator gr = Generator.instance();
>>> GeneratedChartState state;
>>> try
>>> {
>>> state = gr.build(deviceRenderer.getDisplayServer(),
>>> chart,
>>> (Scriptable) null,
>>> bounds,
>>> Locale.getDefault());
>>> 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("TestLineChart");
>>> 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 a line chart model as a reference implementation *
>>> *
>>> * @return An instance of the simulated runtime chart model
>>> * (containing filled datasets)
>>> */
>>> public static final Chart createSimpleLineChart()
>>> {
>>> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
>>> cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
>>> Plot p = cwaBar.getPlot();
>>> p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
>>> 255,
>>> 225));
>>> cwaBar.getTitle().getLabel().getCaption()
>>> .setValue("Sample Line Chart");
>
>>> Legend lg = cwaBar.getLegend();
>>> LineAttributes lia = lg.getOutline();
>>> lg.getText().getFont().setSize(16);
>>> lia.setStyle(LineStyle.SOLID_LITERAL);
>>> lg.getInsets().set(10, 5, 0, 0);
>>> lg.getOutline().setVisible(false);
>>> lg.setAnchor(Anchor.NORTH_LITERAL);
>
>>> AxisImpl xAxisPrimary =
>>> (AxisImpl) cwaBar.getPrimaryBaseAxes()[0];
>>> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
>>> xAxisPrimary.getMajorGrid()
>>> .setTickStyle(TickStyle.BELOW_LITERAL);
>>> xAxisPrimary.getOrigin()
>>> .setType(IntersectionType.VALUE_LITERAL);
>>> xAxisPrimary.getTitle().setVisible(false);
>
>>> AxisImpl yAxisPrimary = (AxisImpl) cwaBar
>>> .getPrimaryOrthogonalAxis(xAxisPrimary);
>>> yAxisPrimary.getMajorGrid()
>>> .setTickStyle(TickStyle.LEFT_LITERAL);
>>> yAxisPrimary.setPercent(true);
>
>>> Vector vs = new Vector();
>>> vs.add("one");
>>> vs.add("two");
>>> vs.add("three");
>
>>> ArrayList vn1 = new ArrayList();
>>> vn1.add(new Double(25));
>>> vn1.add(new Double(35));
>>> vn1.add(new Double(-45));
>
>>> TextDataSet categoryValues = TextDataSetImpl.create(vs);
>>> NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
>
>>> // CREATE THE CATEGORY SERIES
>>> Series seCategory = SeriesImpl.create();
>>> seCategory.setDataSet(categoryValues);
>
>>> // CREATE THE PRIMARY DATASET
>>> LineSeries ls = (LineSeries) LineSeriesImpl.create();
>>> ls.setSeriesIdentifier("My Line Series");
>>> ls.setDataSet(orthoValues1);
>>> ls.getLineAttributes().setColor(ColorDefinitionImpl.CREAM()) ;
>>> ls.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
>>> ls.getLabel().setVisible(true);
>
>>> SeriesDefinition sdX = SeriesDefinitionImpl.create();
>>> sdX.getSeriesPalette().update(0);
>>> xAxisPrimary.getSeriesDefinitions().add(sdX);
>
>>> SeriesDefinition sdY = SeriesDefinitionImpl.create();
>>> sdY.getSeriesPalette().update(1);
>>> yAxisPrimary.getSeriesDefinitions().add(sdY);
>
>>> sdX.getSeries().add(seCategory);
>>> sdY.getSeries().add(ls);
>
>>> return cwaBar;
>>> }
>>> }
>
>
|
|
|
Goto Forum:
Current Time: Sat Jun 07 15:35:16 EDT 2025
Powered by FUDForum. Page generated in 0.03659 seconds
|