Data
Mapping
Before a chart is actually
created, we need to specify the data mapping information to EspressChart.
To do so, we can create an instance of the colInfo class and include this
in the QbChart constructor that we will call.
Explanation:Enable Refresh
Series: Let’s assume we have four sets of two-dimensional data of the same subject (category). If we plot these four sets of data on the same graph, we would have a "series" of four data sets. Pie charts do not support series.Category & Value: If category is the base, the corresponding data will be value. In a vertical column chart, the columns are separated by the category data, X-Axis, while the height represents the value data, Y-Axis. Value data are usually numerical while category data are not necessarily numerical. Category data can be numbers, time, date, or alphabets, i.e. names, groups... etc.
Sub value: also referred to as "2nd value" in EspressChart Designer, sub value index let EspressChart know where to obtain the value of a combination chart.
// Create an colInfo object that specifies infomation on data mappingFor example, consider the following data
// ColInfo(int series, int category, int sumBy, int value, int subvalue)
int series = -1; // use –1 if no series
int category = 0; // category data in column 1, thus, index 0
int sumBy = -1; // use –1 if not used
int value = 2; // value data in column 3, thus, index 2
int subvalue = -1; // not plotting a combination chart, use –1
ColInfo sampleColInfo = new ColInfo(series, category, sumBy, value, subvalue);// Alternatively, a ColInfo object can be constructed as below
ColInfo sampleColInfo = new ColInfo();
sampleColInfo.category=0;
sampleColInfo.value=2;
// QbChart(java.applet.Applet applet, int dimension, int chartType,
// IDatabaseInfo dbinfo, IColumnMap cmap, java.lang.String template)
QbChart chart = new QbChart( null, QbChart.VIEW2D, QbChart.BAR,
yourData, sampleColInfo, null);
Name Year Units Ordered Unit Sold James 1999 34 30 James 2000 43 32 Peter 1999 23 21 Peter 2000 54 39 Sample Data The following ColInfo can be mapped
ColInfo colInfo = new ColInfo();
colInfo.category=0; // The Name column
colInfo.series=1; // The Year column
colInfo.value=2; // The Units Ordered column
colInfo.subvalue=3; // The Units Sold column
// enable speed key (Ctrl + R) to data refresh,Data Points
// right click pop-up menu will still work
chart.setRefreshEnabled(true);
// show top labels for secondary axis
hDataPoints.gethSecondaryLabel().setVisible(true);
// and in your main program create LabelInfo object and pass it
to QbChart
IDataLabelInfo dataLabelInfo = new LabelInfo();
chart.gethDataPoints().setDataLabelInfo(dataLabelInfo);
// For secondary label
chart.gethDataPoints().setSecondaryDataLabelInfo(dataLabelInfo);
// Enable Zooming, can be either DAY, MONTH, or YEAR
IZoomInfo hZoomInfo = chart.gethZoomInfo();
hZoomInfo.setMinScale(1, IZoomInfo.DAY);
hZoomInfo.setMaxScale(7, IZoomInfo.DAY);
hZoomInfo.setScale(1, IZoomInfo.DAY);
hZoomInfo.setZoomEnabled(true);
// EspressChart would "add" when combining 2 data points into 1.
// Available aggregate operators are SUM, AVG, COUNT, MIN and MAX
hZoomInfo.setAggregateOperator(IZoomInfo.SUM);
// if secondary value exists, then secondary aggregate operator
is required
hZoomInfo.setSecondaryAggregateOperator(IZoomInfo.SUM);
// setting upper and lower bounds for the chart created
hZoomInfo.setLowerBound(lower);
hZoomInfo.setUpperBound(upper);
// Set Linear Scale to be true
hZoomInfo.setLinearScale(true);
// EspressChart would "add" when combining 2 data points into 1
// Available aggregate operators are SUM, AVG, COUNT, MIN and MAX
hDrillDown.setAggregateOperator(hDrillDown.SUM);
// set drill down level template name
// first level will be "book_1.tpl", second level: "book_2.tpl"....
hDrillDown.setDrillName("book_");
try {
// EspressChart would "add" when combining 2 data points into 1
// Available aggregate operators are SUM, AVG, COUNT, MIN and MAX
hDrillDown.setAggregateOperator(hDrillDown.SUM);
// set drill down level template name
// "book_1.tpl" will be applied to all the drill down levels
hDrillDown.setDrillName("book_1");
try {
// create an IHyperLinkSet object, "hHyperLinks" that
// has a handle on the chart’s HyperLinks
IHyperLinkSet hHyperLinks = chart.gethHyperLinks();
//links for the Mary category "day" & hint box
// new HyperLink(series, category, sumBy, url, target);
HyperLink temp = new HyperLink( "day","Mary","",
// set the hint box message
temp.setHintValue("Click Here for Mary’s data during days" );
// add the hyperlink to the set
hHyperLinks.add(temp);
// links for both Mary & Peter "night", note the second argument
is
// empty, "", to include all data
hHyperLinks.add(new HyperLink( "night","","",
// revise new link location for Mary "night"
hHyperLinks.add(new HyperLink( "night","Mary","",
// set the lower & upper bounds to null to include all data
points
hHistogramInfo.setLowerBound(null);
hHistogramInfo.setUpperBound(null);
// set the scale step to 1
hHistogramInfo.setScale(new Integer(1));
// show histogram in a linear scale
hHistogramInfo.setHistogram(true);
hHistogramInfo.setLinearScale(true);
// set to round data values to show all data points
hHistogramInfo.setRounded(true);