Hyperlink on chart on webpage
Comments
-
Mann,
You need to add the trigger to the chart model. Keep in mind you will also need to deal with the image map that is created. Take a look at this example. It generates a png and the image map is in the im str. You will need to add the code to include the im into an html page.
Jason
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.PlatformConfig;
import org.eclipse.birt.chart.device.IDeviceRenderer;
import org.eclipse.birt.chart.device.IDisplayServer;
import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.IGenerator;
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.ChartDimension;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.LineStyle;
import org.eclipse.birt.chart.model.attribute.Position;
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.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.LineAttributesImpl;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.NumberDataSet;
import org.eclipse.birt.chart.model.data.TextDataSet;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.impl.SerializerImpl;
import org.eclipse.birt.chart.model.Serializer;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.BarSeries;
import org.eclipse.birt.chart.model.type.LineSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.chart.util.PluginSettings;
import org.eclipse.birt.chart.api.ChartEngine;
import org.eclipse.birt.chart.model.data.*;
import org.eclipse.birt.chart.model.data.impl.*;
import org.eclipse.birt.chart.model.attribute.*;
import org.eclipse.birt.chart.model.attribute.impl.*;
import org.eclipse.birt.chart.device.IImageMapEmitter;
import org.eclipse.birt.chart.device.EmptyUpdateNotifier;
/**
* Test decription:
* </p>
* Chart script: BeforeDrawLegendItem()
* </p>
*/
public class StandaloneChart
{
private static String OUTPUT = "output/Stanalone.png"; //$NON-NLS-1$
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 1L;
/**
* A chart model instance
*/
private Chart cm = null;
/**
* The swing rendering device
*/
private IDeviceRenderer dRenderer = null;
private IDisplayServer dServer = null;
private GeneratedChartState gcs = null;
/**
* execute application
*
* @param args
*/
public static void main( String[] args )
{
new StandaloneChart( );
System.out.println("Finished");
}
/**
* Constructor
*/
public StandaloneChart( )
{
PlatformConfig pf = new PlatformConfig();
pf.setProperty("STANDALONE", true);
//Returns a singleton instance of the Chart Engine
ChartEngine ce = ChartEngine.instance( pf);
//Returns a singleton instance of the Generator
IGenerator gr = ce.getGenerator();
try
{
//device renderers for dv.SWT, dv.PNG, dv.JPG
//dv.PDF, dv.SVG, dv.SWING, dv.PNG24, div.BMP
dRenderer = ce.getRenderer("dv.PNG");
dServer =dRenderer.getDisplayServer( );
}
catch( Exception ex)
{
ex.printStackTrace();
}
//cm = new AfterDatasetFilled().GetChartModel();
cm = StandaloneChart.createColoredByCategoryChart();
BufferedImage img = new BufferedImage(
600,
600,
BufferedImage.TYPE_INT_ARGB );
Graphics g = img.getGraphics( );
Graphics2D g2d = (Graphics2D) g;
//Look at IDeviceRenderer.java for all properties
//like DPI_RESOLUTION
//FILE_IDENTIFIER
//FORMAT_IDENTIFIER
//UPDATE_NOTIFIER
dRenderer.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, g2d );
dRenderer.setProperty( IDeviceRenderer.FILE_IDENTIFIER, OUTPUT ); //$NON-NLS-1$
//Set the bounds for the entire chart
Bounds bo = BoundsImpl.create( 0, 0, 600, 600 );
bo.scale( 72d / dRenderer.getDisplayServer( ).getDpiResolution( ) );
try
{
gcs = gr.build(
dServer,
cm,
bo,
null,
null,
null );
dRenderer.setProperty(IDeviceRenderer.UPDATE_NOTIFIER, new EmptyUpdateNotifier( cm, gcs.getChartModel()));
gr.render( dRenderer, gcs );
String im = ((IImageMapEmitter)dRenderer).getImageMap();
System.out.println(im);
}
catch ( ChartException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}
}
protected static final Chart createColoredByCategoryChart( )
{
//Create chart with or without axes
//Configure blocks
//Configure axis
//Create DataSets
//Create Series and Series Definitions
//Tie the Series Definitions to the axis
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
// Plot
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
cwaBar.getBlock( ).getOutline( ).setVisible( true );
Plot p = cwaBar.getPlot( );
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
255,
225 ) );
p.getOutline( ).setVisible( false );
cwaBar.getTitle( )
.getLabel( )
.getCaption( )
.setValue( "Bar Chart Colored by Category" );//$NON-NLS-1$
// Legend
Legend lg = cwaBar.getLegend( );
lg.getText( ).getFont( ).setSize( 16 );
lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
//LINEAR_LITERAL
//LOGARITHMIC_LITERAL
//TEXT_LITERAL
//DATE_TIME_LITERAL
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );
xAxisPrimary.getTitle( ).getCaption( ).setValue( "Products" );
xAxisPrimary.getTitle( ).setVisible( true );
// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 45 );
yAxisPrimary.getTitle( ).getCaption( ).setValue( "Sales" );//$NON-NLS-1$
yAxisPrimary.getTitle( ).setVisible( true );
//To add another axis use AxisImpl.create( Axis.ORTHOGONAL )
//Then add it to the associated primary base axis like
//.getAssociatedAxes().add( youraxis )
// Data Set
//BubbleDataSetImpl
//DateTimeDataSetImpl
//DifferenceDataSetImpl
//GanttDataSetImpl
//NumberDataSetImpl
//StockDataSetImpl
//TextDataSetImpl
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"Item 1", "Item 2", "Item 3"} );
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{
14.3, 20.9, -7.6
} );
// X-Series
// Use SeriesImpl for base series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
//Tie series to a series definition and tie sd to the axis
//Setup palette, grouping,sorting, and formatspecifier
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( 0 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series
//Use specific series type
//AreaSeriesImpl
//BarSeriesImpl
//BubbleSeriesImpl
//DialSeriesImpl
//DifferenceSeriesImpl
//GanntSeriesImpl
//LineSeriesImpl
//PieSeriesImpl
//ScatterSeriesImpl
//StockSeriesImpl
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
bs.setDataSet( orthoValues );
bs.setRiserOutline( null );
bs.getLabel( ).setVisible( true );
bs.setLabelPosition( Position.INSIDE_LITERAL );
Trigger tr = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL, ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL, TooltipValueImpl.create(500, null)));
bs.getTriggers().add(tr);
//Setup palette, grouping,sorting, and formatspecifier
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( bs );
return cwaBar;
}
}0 -
Hi, jason,
Thanks for your reply. your example is veru help full to me
it is genetating ImageMap in String im variable,but as u say that i hav to
to add the code to include the im into an html page, so how i do this
because i dont know how to pass this ImageMap to html page.
will u help me to get picture more clear that how this code is get included in html page?
please help.........
thanks
mann0 -
Take a look at the modified example<br />
<br />
<br />
<br />
import java.awt.Graphics;<br />
import java.awt.Graphics2D;<br />
import java.awt.image.BufferedImage;<br />
import java.io.FileInputStream;<br />
import java.io.FileOutputStream;<br />
<br />
import org.eclipse.birt.core.framework.Platform;<br />
import org.eclipse.birt.core.framework.PlatformConfig;<br />
import org.eclipse.birt.chart.device.IDeviceRenderer;<br />
import org.eclipse.birt.chart.device.IDisplayServer;<br />
<br />
import org.eclipse.birt.chart.exception.ChartException;<br />
import org.eclipse.birt.chart.factory.GeneratedChartState;<br />
import org.eclipse.birt.chart.factory.IGenerator;<br />
import org.eclipse.birt.chart.model.Chart;<br />
import org.eclipse.birt.chart.model.ChartWithAxes;<br />
import org.eclipse.birt.chart.model.attribute.AxisType;<br />
import org.eclipse.birt.chart.model.attribute.Bounds;<br />
import org.eclipse.birt.chart.model.attribute.ChartDimension;<br />
import org.eclipse.birt.chart.model.attribute.IntersectionType;<br />
import org.eclipse.birt.chart.model.attribute.LegendItemType;<br />
import org.eclipse.birt.chart.model.attribute.LineStyle;<br />
import org.eclipse.birt.chart.model.attribute.Position;<br />
import org.eclipse.birt.chart.model.attribute.TickStyle;<br />
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;<br />
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;<br />
import org.eclipse.birt.chart.model.attribute.impl.LineAttributesImpl;<br />
import org.eclipse.birt.chart.model.component.Axis;<br />
import org.eclipse.birt.chart.model.component.Series;<br />
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;<br />
import org.eclipse.birt.chart.model.data.NumberDataSet;<br />
import org.eclipse.birt.chart.model.data.TextDataSet;<br />
import org.eclipse.birt.chart.model.data.SeriesDefinition;<br />
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;<br />
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;<br />
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;<br />
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;<br />
import org.eclipse.birt.chart.model.impl.SerializerImpl;<br />
import org.eclipse.birt.chart.model.Serializer;<br />
import org.eclipse.birt.chart.model.layout.Legend;<br />
import org.eclipse.birt.chart.model.layout.Plot;<br />
import org.eclipse.birt.chart.model.type.BarSeries;<br />
import org.eclipse.birt.chart.model.type.LineSeries;<br />
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;<br />
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;<br />
import org.eclipse.birt.chart.util.PluginSettings;<br />
import org.eclipse.birt.chart.api.ChartEngine;<br />
import org.eclipse.birt.chart.model.data.*;<br />
import org.eclipse.birt.chart.model.data.impl.*;<br />
import org.eclipse.birt.chart.model.attribute.*;<br />
import org.eclipse.birt.chart.model.attribute.impl.*;<br />
import org.eclipse.birt.chart.device.IImageMapEmitter;<br />
import org.eclipse.birt.chart.device.EmptyUpdateNotifier;<br />
import java.io.*;<br />
<br />
<br />
<br />
/**<br />
* Test decription:<br />
* </p>
* Chart script: BeforeDrawLegendItem()<br />
* </p>
*/<br />
<br />
public class StandaloneChart<br />
{<br />
<br />
private static String OUTPUT = "output/Standalone.png"; //$NON-NLS-1$<br />
private static String OUTPUT_HTML = "output/Standalone.html"; //$NON-NLS-1$<br />
<br />
<br />
/**<br />
* Comment for <code>serialVersionUID</code><br />
*/<br />
private static final long serialVersionUID = 1L;<br />
<br />
/**<br />
* A chart model instance<br />
*/<br />
private Chart cm = null;<br />
<br />
/**<br />
* The swing rendering device<br />
*/<br />
private IDeviceRenderer dRenderer = null;<br />
private IDisplayServer dServer = null;<br />
<br />
<br />
private GeneratedChartState gcs = null;<br />
<br />
/**<br />
* execute application<br />
* <br />
* @param args<br />
*/<br />
public static void main( String[] args )<br />
{<br />
new StandaloneChart( );<br />
System.out.println("Finished");<br />
}<br />
<br />
/**<br />
* Constructor<br />
*/<br />
public StandaloneChart( )<br />
{<br />
PlatformConfig pf = new PlatformConfig();<br />
pf.setProperty("STANDALONE", true);<br />
<br />
//Returns a singleton instance of the Chart Engine<br />
ChartEngine ce = ChartEngine.instance( pf);<br />
//Returns a singleton instance of the Generator<br />
IGenerator gr = ce.getGenerator();<br />
<br />
try<br />
{<br />
//device renderers for dv.SWT, dv.PNG, dv.JPG<br />
//dv.PDF, dv.SVG, dv.SWING, dv.PNG24, div.BMP<br />
dRenderer = ce.getRenderer("dv.PNG");<br />
dServer =dRenderer.getDisplayServer( ); <br />
}<br />
catch( Exception ex)<br />
{<br />
ex.printStackTrace();<br />
}<br />
<br />
//cm = new AfterDatasetFilled().GetChartModel();<br />
cm = StandaloneChart.createColoredByCategoryChart();<br />
<br />
<br />
<br />
<br />
BufferedImage img = new BufferedImage(<br />
600,<br />
600,<br />
BufferedImage.TYPE_INT_ARGB );<br />
Graphics g = img.getGraphics( );<br />
<br />
Graphics2D g2d = (Graphics2D) g;<br />
//Look at IDeviceRenderer.java for all properties<br />
//like DPI_RESOLUTION<br />
//FILE_IDENTIFIER<br />
//FORMAT_IDENTIFIER<br />
//UPDATE_NOTIFIER<br />
dRenderer.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, g2d );<br />
dRenderer.setProperty( IDeviceRenderer.FILE_IDENTIFIER, OUTPUT ); //$NON-NLS-1$<br />
<br />
//Set the bounds for the entire chart<br />
Bounds bo = BoundsImpl.create( 0, 0, 600, 600 );<br />
bo.scale( 72d / dRenderer.getDisplayServer( ).getDpiResolution( ) );<br />
<br />
<br />
try<br />
{<br />
gcs = gr.build(<br />
dServer,<br />
cm,<br />
bo,<br />
null,<br />
null,<br />
null );<br />
dRenderer.setProperty(IDeviceRenderer.UPDATE_NOTIFIER, new EmptyUpdateNotifier( cm, gcs.getChartModel()));<br />
<br />
gr.render( dRenderer, gcs );<br />
String im = ((IImageMapEmitter)dRenderer).getImageMap();<br />
<br />
BufferedWriter out = new BufferedWriter( new FileWriter(OUTPUT_HTML));<br />
<br />
out.write("<html>");<br />
out.newLine();<br />
out.write("<body>");<br />
out.newLine();<br />
out.write("<div>");<br />
out.newLine();<br />
out.write("<map name='testmap'>");<br />
out.write(im);<br />
out.write("</map>");<br />
out.newLine();<br />
out.write( "standalone.png</img>");<br />
out.newLine();<br />
out.write("</div>");<br />
out.newLine(); <br />
out.write("</body>");<br />
out.newLine();<br />
out.write("</html>");<br />
out.newLine();<br />
out.close();<br />
<br />
System.out.println(im);<br />
<br />
}<br />
catch ( Exception e )<br />
{<br />
// TODO Auto-generated catch block<br />
e.printStackTrace( );<br />
}<br />
}<br />
<br />
protected static final Chart createColoredByCategoryChart( )<br />
{<br />
//Create chart with or without axes<br />
//Configure blocks<br />
//Configure axis<br />
//Create DataSets<br />
//Create Series and Series Definitions<br />
//Tie the Series Definitions to the axis<br />
<br />
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );<br />
<br />
// Plot<br />
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );<br />
cwaBar.getBlock( ).getOutline( ).setVisible( true );<br />
Plot p = cwaBar.getPlot( );<br />
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,<br />
255,<br />
225 ) );<br />
p.getOutline( ).setVisible( false );<br />
cwaBar.getTitle( )<br />
.getLabel( )<br />
.getCaption( )<br />
.setValue( "Bar Chart Colored by Category" );//$NON-NLS-1$<br />
<br />
// Legend<br />
Legend lg = cwaBar.getLegend( );<br />
lg.getText( ).getFont( ).setSize( 16 );<br />
lg.setItemType( LegendItemType.CATEGORIES_LITERAL );<br />
<br />
// X-Axis<br />
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];<br />
//LINEAR_LITERAL<br />
//LOGARITHMIC_LITERAL<br />
//TEXT_LITERAL<br />
//DATE_TIME_LITERAL<br />
xAxisPrimary.setType( AxisType.TEXT_LITERAL );<br />
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );<br />
xAxisPrimary.getOrigin( ).setType( IntersectionType.VALUE_LITERAL );<br />
xAxisPrimary.getTitle( ).getCaption( ).setValue( "Products" );<br />
xAxisPrimary.getTitle( ).setVisible( true );<br />
<br />
// Y-Axis<br />
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );<br />
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );<br />
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );<br />
yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 45 );<br />
yAxisPrimary.getTitle( ).getCaption( ).setValue( "Sales" );//$NON-NLS-1$<br />
yAxisPrimary.getTitle( ).setVisible( true );<br />
<br />
//To add another axis use AxisImpl.create( Axis.ORTHOGONAL )<br />
//Then add it to the associated primary base axis like<br />
//.getAssociatedAxes().add( youraxis )<br />
<br />
<br />
// Data Set<br />
//BubbleDataSetImpl<br />
//DateTimeDataSetImpl<br />
//DifferenceDataSetImpl<br />
//GanttDataSetImpl<br />
//NumberDataSetImpl<br />
//StockDataSetImpl<br />
//TextDataSetImpl<br />
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{<br />
"Item 1", "Item 2", "Item 3"} );<br />
NumberDataSet orthoValues = NumberDataSetImpl.create( new double[]{<br />
14.3, 20.9, -7.6<br />
} );<br />
<br />
// X-Series<br />
// Use SeriesImpl for base series<br />
Series seCategory = SeriesImpl.create( );<br />
seCategory.setDataSet( categoryValues );<br />
//Tie series to a series definition and tie sd to the axis<br />
//Setup palette, grouping,sorting, and formatspecifier<br />
SeriesDefinition sdX = SeriesDefinitionImpl.create( );<br />
sdX.getSeriesPalette( ).shift( 0 );<br />
xAxisPrimary.getSeriesDefinitions( ).add( sdX );<br />
sdX.getSeries( ).add( seCategory );<br />
<br />
// Y-Series<br />
//Use specific series type<br />
//AreaSeriesImpl<br />
//BarSeriesImpl<br />
//BubbleSeriesImpl<br />
//DialSeriesImpl<br />
//DifferenceSeriesImpl<br />
//GanntSeriesImpl<br />
//LineSeriesImpl<br />
//PieSeriesImpl<br />
//ScatterSeriesImpl<br />
//StockSeriesImpl<br />
BarSeries bs = (BarSeries) BarSeriesImpl.create( );<br />
bs.setDataSet( orthoValues );<br />
bs.setRiserOutline( null );<br />
bs.getLabel( ).setVisible( true );<br />
bs.setLabelPosition( Position.INSIDE_LITERAL );<br />
<br />
<br />
Trigger tr = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL, ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL, TooltipValueImpl.create(500, null)));<br />
<br />
bs.getTriggers().add(tr);<br />
<br />
//Setup palette, grouping,sorting, and formatspecifier<br />
SeriesDefinition sdY = SeriesDefinitionImpl.create( );<br />
yAxisPrimary.getSeriesDefinitions( ).add( sdY );<br />
sdY.getSeries( ).add( bs );<br />
<br />
return cwaBar;<br />
} <br />
<br />
<br />
}<br />
<br />
Jason0 -
Hi jason,
thanks alot for your reply.
code is working fine.
Now i hav one more issue is :
I wont to show the chart on webpage
i m using the example of servlet to show chart on webpage
so how i add the code of generating ImageMap in that servlet example.
Will u plaese help me..........
Thanks Once Again
mann0 -
If you want to use a servlet, it may be best to use the Chart Tag lib, which takes care of the image map. If you want to do it with your own servlet look at the ChartRenderTag.java class in the source (org.eclipse.birt.chart.viewer project). There is a class ImageHTMLemitter that essentially creates the html page to hold the image and map and pass back to the response.
Jason0 -
Hi jason,
As u say, I search for org.birt.chart.viewer project.
but i got just chart.viewer.jar file
So i m stuck here!!!!!!!!
another thing is
I tried the example by using chart tag lib in which i m passing the java instance.
here is my jsp file which uses chart tag library
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/chart.tld" prefix="chart"%>
<%@page import="com.ibm.icu.util.ULocale"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sample web page of BIRT chart</title>
</head>
<body>
SideBySideBar chart:
<chart:renderChart width="600" height="400" output="jpg"
model="<%=SideBySideBar.createSideBySideBar( )%>">
</chart:renderChart>
And SideBySideBar.java
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.ActionType;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.TriggerCondition;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.TooltipValueImpl;
import org.eclipse.birt.chart.model.attribute.impl.URLValueImpl;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.BaseSampleData;
import org.eclipse.birt.chart.model.data.DataFactory;
import org.eclipse.birt.chart.model.data.NumberDataSet;
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.TextDataSet;
import org.eclipse.birt.chart.model.data.Trigger;
import org.eclipse.birt.chart.model.data.impl.ActionImpl;
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.TriggerImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.BarSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
public class SideBySideBar
{
public static Chart createSideBySideBar( )
{
//model="<%=SampleHelper.createSampleChart( )%>">
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
cwaBar.setType( "Bar Chart" );
cwaBar.setSubType( "Side-by-side" ); //$NON-NLS-1$
// Plot
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
cwaBar.getBlock( ).getOutline( ).setVisible( true );
Plot p = cwaBar.getPlot( );
p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255,
255,
225 ) );
// Title
cwaBar.getTitle( )
.getLabel( )
.getCaption( )
.setValue( "Side-by-side Bar Chart" ); //$NON-NLS-1$
// Legend
Legend lg = cwaBar.getLegend( );
lg.setItemType( LegendItemType.CATEGORIES_LITERAL );
// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );
// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );
// Data Set
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{
25, 35, 15, 5, 20
} );
NumberDataSet orthoValues2 = NumberDataSetImpl.create( new double[]{
5, 10, 25, 10, 5
} );
SampleData sd = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$
sd.getBaseSampleData( ).add( sdBase );
OrthogonalSampleData sdOrthogonal1 = DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal1.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal1.setSeriesDefinitionIndex( 0 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal1 );
OrthogonalSampleData sdOrthogonal2 = DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal2.setDataSetRepresentation( "" );//$NON-NLS-1$
sdOrthogonal2.setSeriesDefinitionIndex( 1 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal2 );
cwaBar.setSampleData( sd );
// X-Series
Series seCategory = SeriesImpl.create( );
seCategory.setDataSet( categoryValues );
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( 0 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series
BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );
bs1.setDataSet( orthoValues1 );
bs1.getLabel( ).setVisible( true );
bs1.setLabelPosition( Position.INSIDE_LITERAL );
BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
bs2.setDataSet( orthoValues2 );
bs2.getLabel( ).setVisible( true );
bs2.setLabelPosition( Position.INSIDE_LITERAL );
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( bs1 );
sdY.getSeries( ).add( bs2 );
return cwaBar;
}
}
I m just calling createSideBySideChart() in my jsp file.
So it is working fine . i m able to see the chart on webpage.
but How it generate ImageMap? As u say Chart TagLib generate Image map.
So which tag i shd use for that? OR Any coading is required in SideBySideBar.java file.
plesae help for this
Thanks
mann0 -
Look at this post.<br />
<br />
<a class='bbc_url' href='http://www.birt-exchange.com/modules/vbulletin/showpost.php?p=31802&postcount=12'>http://www.birt-exchange.com/modules/vbulletin/showpost.php?p=31802&postcount=12</a>0 -
Hi Jason,
your code is very helpful for me.now I m able to generate tooltip on chart on web page.
I tryied the code for StackedBarChart to show tooltip,but it just show the tooltip for uppaer series i.e the last series not for all series.........
Why this is happening?
this is the code that i m using
BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );
bs1.setDataSet( orthoValues1 );
bs1.setStacked( true );
bs1.getLabel( ).setVisible( true );
bs1.setLabelPosition( Position.INSIDE_LITERAL );
BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
bs2.setDataSet( orthoValues2 );
bs2.setStacked( true );
bs2.getLabel( ).setVisible( true );
bs2.setLabelPosition( Position.INSIDE_LITERAL );
Trigger tr1 = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL, ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL, TooltipValueImpl.create(200, null)));
Trigger tr2= TriggerImpl.create(TriggerCondition.ONCLICK_LITERAL, ActionImpl.create(ActionType.URL_REDIRECT_LITERAL, URLValueImpl.create(
"https://www.google.com" ,null ,"component","value","")));
bs1.getTriggers().add(tr1);
bs1.getTriggers().add(tr2);
bs2.getTriggers().add(tr1);
bs2.getTriggers().add(tr2);
but it is just showing the tooltip and Hyperlink for bs2(BaseSeries)
plesae help.......
once again thanks for your help
mann0 -
Create tr3 and 4 for the second bar series. You have to create unique ones for all series.
i believe this is a limitation of emf, although you should be able to make a copy.
Trigger tr3 = (Trigger)EcoreUtil.copy( tr1);
Trigger tr4 = (Trigger)EcoreUtil.copy( tr2);
bs1.getTriggers().add(tr1);
bs1.getTriggers().add(tr2);
bs2.getTriggers().add(tr3);
bs2.getTriggers().add(tr4);
Jason0 -
Hi jaosn,
your code is very helpful to me, it is showing tooltip succesfully.
Now i hav one more issue that is i want to create Data of StackedBar for chart tag library.
as u say when we use .chart file to show chart on webpage,we hav to write another java class which provides the data to that .chart file.
now I want to create Datafile for StackedBarChart ,How I create it ?
because in StackedBarChart we hav multiple series,so how to create the data for multiple series? I tryied to create Data class file for multiple series but I m not getting anything.It just show one series data on chart.
Because in your given example of PieChart DataForChartTag class just create the data for one series.
Will u please help for it..........
thanks in advance
mann0 -
A couple of things
When creating the stacked bar try creating a series definition for each bar series
Trigger tr1 = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL, ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL, TooltipValueImpl.create(200, null)));
Trigger tr2= TriggerImpl.create(TriggerCondition.ONCLICK_LITERAL, ActionImpl.create(ActionType.URL_REDIRECT_LITERAL, URLValueImpl.create("http://www.google.com target=_blank" ,null ,"","","")));
Trigger tr3 = (Trigger)EcoreUtil.copy( tr1);
Trigger tr4 = (Trigger)EcoreUtil.copy( tr2);
bs1.getTriggers().add(tr1);
bs1.getTriggers().add(tr2);
bs2.getTriggers().add(tr3);
bs2.getTriggers().add(tr4);
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
sdY.getSeriesPalette( ).shift( 0 );
SeriesDefinition sdY1 = SeriesDefinitionImpl.create( );
sdY1.getSeriesPalette( ).shift( 1 );
sdY.getSeries( ).add( bs1 );
sdY1.getSeries( ).add( bs2 );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
yAxisPrimary.getSeriesDefinitions( ).add( sdY1 );
Then Instead of using the simple data provider, write your own like:
package my.chart.data;
import org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator;
import org.eclipse.birt.chart.integrate.SimpleDataRowExpressionEvaluator;
public class DataForStackedChart {
public static IDataRowExpressionEvaluator getChartData(){
final Object[][] data =
new Object[][]
{{"item1", new Integer( 25 ), new Integer(5)},
{"item2", new Integer( 35 ), new Integer(10)},
{"item3", new Integer( 15 ), new Integer(25)},
{"item4", new Integer( 5 ), new Integer(10)},
{"item5", new Integer( 20 ), new Integer(5)}};
//return new SimpleDataRowExpressionEvaluator( set, data);
return new IDataRowExpressionEvaluator( ) {
int idx = 0;
public void close( )
{
}
public Object evaluate( String expression )
{
if ( "col1".equals( expression ) )
{
return data[idx][0];
}
else if ( "col2".equals( expression ) )
{
return data[idx][1];
}
else if ( "col3".equals( expression ) )
{
return data[idx][2];
}
return expression;
}
public Object evaluateGlobal( String expression )
{
return evaluate( expression );
}
public boolean first( )
{
idx = 0;
return true;
}
public boolean next( )
{
idx++;
return ( idx < 5 );
}
};
}
}
You will notice that the expressions are col1, col2, and col3, when you create your Query set the expression appropriately. For example
BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
Query yQ2 = QueryImpl.create( "col3" );
bs2.getDataDefinition().add(yQ2);
Jason0 -
Hi jason ,
Thanks alot for your reply.I m able to generate most of the charts now.
I m trying Bar-stick Stock chart,but i m not able to generate data for it
this is my DataSet class
package birt.chart.examples;
import org.eclipse.birt.chart.datafeed.StockEntry;
import org.eclipse.birt.chart.util.CDateTime;
import org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator;
import org.eclipse.birt.chart.integrate.SimpleDataRowExpressionEvaluator;
import com.ibm.icu.util.Calendar;
public class BarStickStockDataSet {
public static IDataRowExpressionEvaluator getChartData(){
String[] set = { "cat-1", "val-1" };
Object[][] data = {
{
new CDateTime( 2004, 12, 27 ),
new CDateTime( 2004, 12, 23 ),
new CDateTime( 2004, 12, 22 ),
new CDateTime( 2004, 12, 21 ),
new CDateTime( 2004, 12, 20 ),
new CDateTime( 2004, 12, 17 ),
new CDateTime( 2004, 12, 16 ),
new CDateTime( 2004, 12, 15 )
},
{
new StockEntry( 27.01, 27.00, 28.42, 27.85 ),
new StockEntry( 26.87, 25.15, 27.83, 27.01 ),
new StockEntry( 26.84, 26.00, 27.78, 26.97 ),
new StockEntry( 27.00, 25.17, 27.94, 27.07 ),
new StockEntry( 26.01, 25.15, 28.39, 26.95 ),
new StockEntry( 27.00, 24.76, 27.80, 26.96 ),
new StockEntry( 27.15, 25.28, 28.01, 27.16 ),
new StockEntry( 27.22, 24.80, 28.07, 27.11 ),
}
};
return new SimpleDataRowExpressionEvaluator( set, data);
}
}
In my case it is generating .chart file.
by i m not able to see chart on webPage.
I think there is problem for data generation for .chart file
Is my code is correct for the data OR something else is required?
If yes will u please provide the code for data generation .
please help.........
thanks once again
mann0 -
I m getting this Exception while rendering Bar-stick Stock chart on web
Apr 23, 2008 5:51:33 PM org.eclipse.birt.chart.exception.ChartException logThis
WARNING: Exception
org.eclipse.birt.chart.exception.ChartException: The data entries bound to the s
tock series are incomplete. They must contain four values: High, Low, Open and C
lose.
at org.eclipse.birt.chart.datafeed.StockDataSetProcessorImpl.validateSto
ckEntryData(StockDataSetProcessorImpl.java:98)
at org.eclipse.birt.chart.datafeed.StockDataSetProcessorImpl.populate(St
ockDataSetProcessorImpl.java:62)
at org.eclipse.birt.chart.internal.datafeed.DataProcessor.fillSeriesData
Set(DataProcessor.java:1245)
at org.eclipse.birt.chart.internal.datafeed.DataProcessor.generateRuntim
eSeries(DataProcessor.java:722)
at org.eclipse.birt.chart.internal.datafeed.DataProcessor.generateRuntim
eSeries(DataProcessor.java:435)
at org.eclipse.birt.chart.factory.Generator.bindData(Generator.java:572)
at org.eclipse.birt.chart.viewer.internal.util.ChartImageManager.generat
eStream(Unknown Source)
at org.eclipse.birt.chart.viewer.internal.util.ChartImageManager.generat
eImage(Unknown Source)
at org.eclipse.birt.chart.viewer.internal.util.ChartImageManager.<init>(
Unknown Source)
at org.eclipse.birt.chart.viewer.internal.ChartRendererTag.doEndTag(Unkn
own Source)
at org.apache.jsp.index1123_jsp._jspService(index1123_jsp.java:441)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
29)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:689)
at java.lang.Thread.run(Unknown Source)
org.eclipse.birt.chart.exception.ChartException: The data entries bound to the s
tock series are incomplete. They must contain four values: High, Low, Open and C
lose.
at org.eclipse.birt.chart.datafeed.StockDataSetProcessorImpl.validateSto
ckEntryData(StockDataSetProcessorImpl.java:98)
at org.eclipse.birt.chart.datafeed.StockDataSetProcessorImpl.populate(St
ockDataSetProcessorImpl.java:62)
at org.eclipse.birt.chart.internal.datafeed.DataProcessor.fillSeriesData
Set(DataProcessor.java:1245)
at org.eclipse.birt.chart.internal.datafeed.DataProcessor.generateRuntim
eSeries(DataProcessor.java:722)
at org.eclipse.birt.chart.internal.datafeed.DataProcessor.generateRuntim
eSeries(DataProcessor.java:435)
at org.eclipse.birt.chart.factory.Generator.bindData(Generator.java:572)
at org.eclipse.birt.chart.viewer.internal.util.ChartImageManager.generat
eStream(Unknown Source)
at org.eclipse.birt.chart.viewer.internal.util.ChartImageManager.generat
eImage(Unknown Source)
at org.eclipse.birt.chart.viewer.internal.util.ChartImageManager.<init>(
Unknown Source)
at org.eclipse.birt.chart.viewer.internal.ChartRendererTag.doEndTag(Unkn
own Source)
at org.apache.jsp.index1123_jsp._jspService(index1123_jsp.java:441)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
29)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:689)
at java.lang.Thread.run(Unknown Source)
and one more think I m facing the same problem for BarChart with 2D in depth.
not able to generate data for it......
please help......
thanks
mann0 -
Mann,
Try writting your data class like this
public class DataForStockChart {
public static IDataRowExpressionEvaluator getChartData(){
final Calendar[] dsDateValues = new Calendar[]{
new CDateTime( 2004, 12, 27 ),
new CDateTime( 2004, 12, 23 ),
new CDateTime( 2004, 12, 22 ),
new CDateTime( 2004, 12, 21 ),
new CDateTime( 2004, 12, 20 ),
new CDateTime( 2004, 12, 17 ),
new CDateTime( 2004, 12, 16 ),
new CDateTime( 2004, 12, 15 )
};
final StockEntry[] dsStockValues = new StockEntry[]{
new StockEntry( 27.01, 26.82, 28.02, 26.85 ),
new StockEntry( 26.87, 26.15, 28.83, 27.01 ),
new StockEntry( 26.84, 26.15, 28.78, 26.97 ),
new StockEntry( 27.00, 26.17, 29.94, 27.07 ),
new StockEntry( 27.01, 26.15, 28.89, 26.95 ),
new StockEntry( 27.00, 26.32, 29.80, 26.96 ),
new StockEntry( 27.15, 26.28, 28.01, 27.16 ),
new StockEntry( 27.22, 26.40, 29.07, 27.11 )
};
final double[] dsStockVolume = new double[]{
55958500,
65801900,
63651900,
94646096,
85552800,
126184400,
88997504,
106303904
} ;
//return new SimpleDataRowExpressionEvaluator( set, data);
return new IDataRowExpressionEvaluator( ) {
int idx = 0;
public void close( )
{
}
public Object evaluate( String expression )
{
if ( "date".equals( expression ) )
{
return dsDateValues[idx];
}
else if ( "volume".equals( expression ) )
{
return dsStockVolume[idx];
}
else if ( "high".equals( expression ) )
{
return dsStockValues[idx].getHigh();
}
else if ( "low".equals( expression ) )
{
return dsStockValues[idx].getLow();
}
else if ( "open".equals( expression ) )
{
return dsStockValues[idx].getOpen();
}
else if ( "close".equals( expression ) )
{
return dsStockValues[idx].getClose();
}
return expression;
}
public Object evaluateGlobal( String expression )
{
return evaluate( expression );
}
public boolean first( )
{
idx = 0;
return true;
}
public boolean next( )
{
idx++;
return ( idx < 8 );
}
};
}
}
Then when creating the stock chart use a list for the query definition like the following:
public final static Chart createStockChart( )
{
ChartWithAxes cwaStock = ChartWithAxesImpl.create( );
cwaStock.getLegend( ).setVisible(false);
cwaStock.getTitle( ).getLabel( ).getCaption( ).setValue( "Stock Chart" );//$NON-NLS-1$
// X-Axis
Axis xAxisPrimary = ( (ChartWithAxesImpl) cwaStock ).getPrimaryBaseAxes( )[0];
xAxisPrimary.getTitle( ).getCaption( ).setValue( "Date" );//$NON-NLS-1$
xAxisPrimary.setType( AxisType.DATE_TIME_LITERAL );
xAxisPrimary.setCategoryAxis( true );
xAxisPrimary.getTitle().setVisible(false);
xAxisPrimary.getLabel().getCaption().getFont().setRotation(65);
// Y-Axis (1)
Axis yAxisPrimary = ( (ChartWithAxesImpl) cwaStock ).getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getTitle().getCaption( ).setValue( "Price Axis" );//$NON-NLS-1$
yAxisPrimary.getTitle().setVisible(true);//$NON-NLS-1$
yAxisPrimary.getScale( ).setMax( NumberDataElementImpl.create( 180000000 ) );
yAxisPrimary.getScale( ).setMin( NumberDataElementImpl.create( 20000000 ) );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
yAxisPrimary.setTitlePosition( Position.LEFT_LITERAL );
yAxisPrimary.getTitle().setVisible(false);
// Y-Axis (2)
Axis yAxisOverlay = AxisImpl.create( Axis.ORTHOGONAL );
yAxisOverlay.getTitle( ).getCaption( ).setValue( "Volume" );//$NON-NLS-1$
//yAxisOverlay.getTitle( ).setVisible( true );
yAxisOverlay.setType( AxisType.LINEAR_LITERAL );
yAxisOverlay.getScale( ).setMin( NumberDataElementImpl.create( 20.5 ) );
yAxisOverlay.getScale( ).setMax( NumberDataElementImpl.create( 30.0 ) );
yAxisOverlay.getScale( ).setStep( 0.5 );
xAxisPrimary.getAssociatedAxes( ).add( yAxisOverlay );
// X-Series
Series seBase = SeriesImpl.create( );
//seBase.setDataSet( dsDateValues );
Query dateq = QueryImpl.create("date");
seBase.getDataDefinition().add(dateq);
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( -1 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seBase );
// Y-Series
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
//bs.setRiserOutline( null );
//bs.setDataSet( dsStockVolume );
Query volumeq = QueryImpl.create("volume");
bs.getDataDefinition().add(volumeq);
StockSeries ss = (StockSeries) StockSeriesImpl.create( );
ss.setSeriesIdentifier( "Stock Price" );//$NON-NLS-1$
ss.getLineAttributes( ).setColor( ColorDefinitionImpl.BLUE( ) );
//ss.setDataSet( dsStockValues );
Query q1 = QueryImpl.create("high");
Query q2 = QueryImpl.create("low");
Query q3 = QueryImpl.create("open");
Query q4 = QueryImpl.create("close");
ArrayList list = new ArrayList();
list.add(q1);
list.add(q2);
list.add(q3);
list.add(q4);
ss.getDataDefinition().addAll(list);
SeriesDefinition sdY1 = SeriesDefinitionImpl.create( );
sdY1.getSeriesPalette( ).update( ColorDefinitionImpl.CYAN( ) );
SeriesDefinition sdY2 = SeriesDefinitionImpl.create( );
sdY2.getSeriesPalette( ).update( ColorDefinitionImpl.GREEN( ) );
yAxisPrimary.getSeriesDefinitions( ).add( sdY2 );
sdY1.getSeries( ).add( ss );
yAxisOverlay.getSeriesDefinitions( ).add( sdY1 );
sdY2.getSeries( ).add( bs );
return cwaStock;
}0
Categories
- All Categories
- 107 Developer Announcements
- 53 Articles
- 105 General Questions
- 141 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 898 Cloud Fax and Notifications
- 76 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 118 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management