Bug 167126 - Add dynamic data to a chart's elements
Summary: Add dynamic data to a chart's elements
Status: RESOLVED WONTFIX
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 enhancement (vote)
Target Milestone: 2.3.0 RC1   Edit
Assignee: Yulin Wang CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
Depends on:
Blocks:
 
Reported: 2006-12-07 12:47 EST by Andreas Rentschler CLA
Modified: 2008-05-12 22:39 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Rentschler CLA 2006-12-07 12:47:13 EST
I want to add units to a line chart's axes dynamically, e.g. "time [ns]". The type is available from my data set bound to the chart, but it seems to me that I can't dynamically set it with an expression like: 
row["TimeUnit"]

function beforeDrawAxisTitle( axis, label, context ) {
    if(label.getCaption().getValue() == "time") {
        label.getCaption().setValue(label.getCaption().getValue() +
            DataSetRow[TimeUnit]);
    }
}

There's a trick how to retrieve data within a chart's scripting context, as described by David Michonneau:

> You need to bind this column to a series, and make the series
> invisible. Then you can access the data from the series.

However, this trick does not work in a scatter chart, where I can only bind a column of numerical values to a value series.
Comment 1 David Michonneau CLA 2006-12-07 15:40:46 EST
Investigate how to add access to databound columns within chart scripts.
Comment 2 David Michonneau CLA 2007-03-29 05:35:34 EDT
we need more time to work out how to integrate the scripting contexts
Comment 3 Yulin Wang CLA 2008-05-12 03:49:16 EDT
The axis label is auto generated by chart engine, according to the min/max value of series. Hence, it's impossible to generate a dynamic axis label according to each series value. Series and Axis are not one-one mapping, so you could not write the series value to axis script.
I'm not clear to your use case, but I have a solution to my use case.
For instance, you have a table data set as follows:
Category/Value
A/5000
B/10000
C/20000
and you want to display the y axis like: 0, 5k, 10k, 20k
you could write the script like this:
function beforeDrawAxisTitle( axis, label, context ) {
    if(label.getCaption().getValue() >1000 && label.getCaption().getValue()<1000000) {
        label.getCaption().setValue(label.getCaption().getValue()/1000 + "K");
    }
}

If you separate the value to measure and unit, for instance,
Category/Measure/Unit
A/5/K
B/10/K
C/20/K
Chart can't render the value properly, because query definition only consumes the "measure" data without considering "unit".
So I suggest you use the previous example to add dynamic unit to axis label.

Comment 4 Yulin Wang CLA 2008-05-12 22:39:54 EDT
Sorry for my mistake, I thought it was beforeDrawAxesLabels in script. This use case is not general, because the units can be various. It only resolves the issue under some assumed conditions. So we still have to resolve this specific issue by scripts, without adding general engine support.

For your use case, assuming there is a tabular data set as follows:
Category        Value      Units
A/1     3     ns
B/2     4     ns
C/3     5     ns

you can still create two series just like the trick:
Series 1: category series query definition is row[“Category”], value series query definition is row[“Value”]
Series 2: category series query definition is row[“ns”], value series query definition is row[“Value”]

You should set the second series invisible, and get the category value row[“ns”] from the second series and set it to axis title. Even if the category value is numerical rather than category, no matter Scatter or Line chart, you could set Category X axis in UI.
According to the description, you may thinks it’s impossible to get value from Scatter chart, but possible to get it from Line chart. The only difference between them is Scatter chart has a linear X axis by default. However, you still can set it as category X axis in UI.
If you must use linear X axis, you could try Bubble chart. Bubble chart has the linear X axis, and accept the String in value series's query definition.
That is to say, you create a second invisible Bubble series, and set the units to this series's Y value, so you can get the units. In addition, you set a constant value in first Bubble series's size, so it behaves like Scatter. 

Sample:
Bubble Series 1: category series query definition is row[“Category”], value series Y value is row[“Value”], Size is 1.
Bubble Series 2: category series query definition is row[“Category”], value series Y value is row["ns"], Size is 1.

Now you still can use this trick to meet your requirement.
Thanks