|
Re: Problem with label size, auto-scale not working properly [message #360652 is a reply to message #360647] |
Thu, 14 February 2008 22:29 |
Eclipse User |
|
|
|
Originally posted by: jasonweathersby.alltel.net
Does setting the max to say 400 work? Meaning do not call getmax, just
try to set it.
R.Uhalde wrote:
> Hi,
>
> I'm working with a bar chart (pareto chart) with very long labels. The
> problem is that autoscaling is putting my first label partially outside
> of chart canvas. See attachment.
>
>
> I've tried to set MAX scale with a script like this:
>
>
> function beforeGeneration(chart, icsc)
> {
> importPackage(Packages.org.eclipse.birt.chart.model);
> importPackage(Packages.org.eclipse.birt.chart.model.data);
> importPackage(Packages.org.eclipse.birt.chart.model.data.imp l);
>
> var anaxis = chart.getPrimaryBaseAxes()[0];
> var amax = chart.getPrimaryOrthogonalAxis(anaxis).getScale().getMax();
> var max = NumberDataElementImpl.create( amax.getValue() * 1.33 );
> chart.getPrimaryOrthogonalAxis(anaxis).getScale().setMax(max );
> }
>
> But I always get NULL in getScale().getMax().
>
> Is this a bug or I'm missing something??
>
> Thanks in advance.
>
> ------------------------------------------------------------ ------------
>
|
|
|
Re: Problem with label size, auto-scale not working properly [message #360654 is a reply to message #360652] |
Fri, 15 February 2008 01:06 |
Ricardo Uhalde Messages: 30 Registered: July 2009 |
Member |
|
|
Jason Weathersby escreveu:
> Does setting the max to say 400 work? Meaning do not call getmax, just
> try to set it.
>
>
>
> R.Uhalde wrote:
>> Hi,
>>
>> I'm working with a bar chart (pareto chart) with very long labels. The
>> problem is that autoscaling is putting my first label partially
>> outside of chart canvas. See attachment.
>>
>>
>> I've tried to set MAX scale with a script like this:
>>
>>
>> function beforeGeneration(chart, icsc)
>> {
>> importPackage(Packages.org.eclipse.birt.chart.model);
>> importPackage(Packages.org.eclipse.birt.chart.model.data);
>> importPackage(Packages.org.eclipse.birt.chart.model.data.imp l);
>> var anaxis = chart.getPrimaryBaseAxes()[0];
>> var amax = chart.getPrimaryOrthogonalAxis(anaxis).getScale().getMax();
>> var max = NumberDataElementImpl.create( amax.getValue() * 1.33 );
>> chart.getPrimaryOrthogonalAxis(anaxis).getScale().setMax(max );
>> }
>>
>> But I always get NULL in getScale().getMax().
>>
>> Is this a bug or I'm missing something??
>>
>> Thanks in advance.
>>
>> ------------------------------------------------------------ ------------
>>
Hi Jason,
Sure it does, but the problem is that results are very sparse, sometimes
are from 1 to 20 , sometimes from 30 to 400, etc. Its impossible to
set a fixed limit due to variety of data.
I could recode my stored procedure to give MAX value and then read from
there to set with getScale.setMax() but that is not the best solution
at all.
Is there another way to know max value of a dataset with BIRT??
|
|
|
Re: Problem with label size, auto-scale not working properly [message #360672 is a reply to message #360654] |
Fri, 15 February 2008 16:48 |
Scott Rosenbaum Messages: 425 Registered: July 2009 |
Senior Member |
|
|
R.Uhalde,
I did this in Java, but the following Java Event Handler code will figure
the Max and Min value from all of the data. I actually round up the max
and min values up and down, so that my data fits in the scale.
Scott Rosenbaum
public class ChartDualY_EventHandler implements IChartEventHandler {
private static Logger logger = Logger.getLogger(ChartDualY_EventHandler.class.getName());
/**
* If you have dual Y-Axis chart, the chart engine generates the
* scale for the axis indpendently. This will go through the data
* from both series and set the scale for both axis to be the same.
*
*/
public void beforeGeneration(Chart chart, IChartScriptContext icsc) {
ChartWithAxes cwa = (ChartWithAxes) chart;
Axis[] xAxisArray = cwa.getBaseAxes();
Axis[] yAxisArray = cwa.getOrthogonalAxes(xAxisArray[0], true);
// find the top and bottom data elements
MinMaxVals mmVals = setMinMax(cwa);
yAxisArray[0].getScale().setMax(NumberDataElementImpl.create (mmVals.getMaxVal()));
yAxisArray[0].getScale().setMin(NumberDataElementImpl.create (mmVals.getMinVal()));
yAxisArray[1].getScale().setMax(NumberDataElementImpl.create (mmVals.getMaxVal()));
yAxisArray[1].getScale().setMin(NumberDataElementImpl.create (mmVals.getMinVal()));
}
private MinMaxVals setMinMax(ChartWithAxes chart) {
Double topDog = new Double(0);
Double lowDog = new Double(0);
// walk through the series, look for top values
for (int i = 0; i < 10; i++) {
Series[] zVal = chart.getSeries(i);
for (int j = 0; j < zVal.length; j++) {
DataSet ds = zVal[j].getDataSet();
Object obj = ds.getValues();
if (obj instanceof Double[]) {
Double[] vals = (Double[]) obj;
for (int k = 0; k < vals.length; k++) {
if (topDog < vals[k]) {
topDog = vals[k];
}
if (lowDog > vals[k]) {
lowDog = vals[k];
}
}
}
}
}
return new MinMaxVals(round(lowDog, "DOWN"), round(topDog, "UP"));
}
// Round up the raw data values to use in the scale
private Integer round(Double num, String direction) {
Double rndVal = Double.valueOf(0);
if ("UP".equalsIgnoreCase(direction)) {
rndVal = num * Double.valueOf(1.1);
} else {
if (num < 0) {
rndVal = num * Double.valueOf(1.1);
} else {
rndVal = num * Double.valueOf(.8);
}
}
return rndVal.intValue();
}
private class MinMaxVals {
private final Integer minVal;
private final Integer maxVal;
private MinMaxVals(Integer minVal, Integer maxVal) {
this.minVal = minVal;
this.maxVal = maxVal;
}
public Integer getMinVal() {
return minVal;
}
public Integer getMaxVal() {
return maxVal;
}
}
}
> I could recode my stored procedure to give MAX value and then read
> from there to set with getScale.setMax() but that is not the best
> solution at all.
>
> Is there another way to know max value of a dataset with BIRT??
>
|
|
|
Re: Problem with label size, auto-scale not working properly [message #360674 is a reply to message #360672] |
Fri, 15 February 2008 19:21 |
Ricardo Uhalde Messages: 30 Registered: July 2009 |
Member |
|
|
Scott Rosenbaum escreveu:
> R.Uhalde,
>
> I did this in Java, but the following Java Event Handler code will
> figure the Max and Min value from all of the data. I actually round up
> the max and min values up and down, so that my data fits in the scale.
>
> Scott Rosenbaum
>
>
>
> public class ChartDualY_EventHandler implements IChartEventHandler {
> private static Logger logger =
> Logger.getLogger(ChartDualY_EventHandler.class.getName());
>
> /**
> * If you have dual Y-Axis chart, the chart engine generates the
> * scale for the axis indpendently. This will go through the data
> * from both series and set the scale for both axis to be the same.
> * */
> public void beforeGeneration(Chart chart, IChartScriptContext icsc) {
>
> ChartWithAxes cwa = (ChartWithAxes) chart;
> Axis[] xAxisArray = cwa.getBaseAxes();
> Axis[] yAxisArray = cwa.getOrthogonalAxes(xAxisArray[0], true);
>
> // find the top and bottom data elements
> MinMaxVals mmVals = setMinMax(cwa);
>
>
> yAxisArray[0].getScale().setMax(NumberDataElementImpl.create (mmVals.getMaxVal()));
>
>
> yAxisArray[0].getScale().setMin(NumberDataElementImpl.create (mmVals.getMinVal()));
>
>
> yAxisArray[1].getScale().setMax(NumberDataElementImpl.create (mmVals.getMaxVal()));
>
>
> yAxisArray[1].getScale().setMin(NumberDataElementImpl.create (mmVals.getMinVal()));
>
>
> }
>
> private MinMaxVals setMinMax(ChartWithAxes chart) {
> Double topDog = new Double(0);
> Double lowDog = new Double(0);
>
> // walk through the series, look for top values
> for (int i = 0; i < 10; i++) {
> Series[] zVal = chart.getSeries(i);
> for (int j = 0; j < zVal.length; j++) {
> DataSet ds = zVal[j].getDataSet();
> Object obj = ds.getValues();
> if (obj instanceof Double[]) {
> Double[] vals = (Double[]) obj;
> for (int k = 0; k < vals.length; k++) {
> if (topDog < vals[k]) {
> topDog = vals[k];
> }
> if (lowDog > vals[k]) {
> lowDog = vals[k];
> }
> }
> }
> }
> }
> return new MinMaxVals(round(lowDog, "DOWN"), round(topDog, "UP"));
> }
>
> // Round up the raw data values to use in the scale
> private Integer round(Double num, String direction) {
> Double rndVal = Double.valueOf(0);
> if ("UP".equalsIgnoreCase(direction)) {
> rndVal = num * Double.valueOf(1.1);
> } else {
> if (num < 0) {
> rndVal = num * Double.valueOf(1.1);
> } else {
> rndVal = num * Double.valueOf(.8);
> }
> }
>
> return rndVal.intValue();
> }
>
> private class MinMaxVals {
> private final Integer minVal;
> private final Integer maxVal;
>
> private MinMaxVals(Integer minVal, Integer maxVal) {
> this.minVal = minVal;
> this.maxVal = maxVal;
> }
>
> public Integer getMinVal() {
> return minVal;
> }
>
> public Integer getMaxVal() {
> return maxVal;
> }
>
> }
> }
>
>
>
>> I could recode my stored procedure to give MAX value and then read
>> from there to set with getScale.setMax() but that is not the best
>> solution at all.
>>
>> Is there another way to know max value of a dataset with BIRT??
>>
>
>
Thanks a lot Scott, your post was really very helpful. Cheers mate! Ricado.
|
|
|
Powered by
FUDForum. Page generated in 0.03936 seconds