Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Bar Chart - X Axys label with Y Serie 2 value
Ilija Angulovich
<p>Hi everyone,</p>
<p> </p>
<p>I´m using open source Birt 4.2.0 and trying to design a Bar Chart with 2 "Y series". One with a value and other with the accumulated. In the X serie i put the year and all is grouping by the year.</p>
<p> </p>
<p>In the X label i want to put the value corresponding with the Second serie of the Y Axis (the value of the year).</p>
<p> </p>
<p>I´ve tryed to do it like this:</p>
<pre class="_prettyXprint _lang-js">
var index = null;
var maxSerie = null;
var counter = 0;
var listVentas;
function beforeGeneration( chart, icsc ) {
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
sd = chart.getAxes().get(0).getAssociatedAxes().get(0).getSeriesDefinitions().get(1);
rs = sd.getRunTimeSeries();
//Inicio contador del total de los valores para la linea de la derecha
var contTotal = 0 ;
var max = 0;
listVentas = rs.get(0).getDataSet().getValues();
for (var i = 0; i < listVentas.length; i++){
contTotal = contTotal + listVentas[i];
if (listVentas[i] > max){
max = listVentas[i];
maxSerie = max;
index = i;
}
}
}
function beforeDrawDataPoint(dph, fill, icsc)
{
temp = dph.getOrthogonalValue();
tempF = maxSerie;
if(dph.getIndex() == index && temp == tempF && counter == 0) {
fill.set(185, 206, 149);
counter += 1;
}
}
function beforeDrawDataPointLabel( dph, label, icsc )
{
var mylab = listVentas[dph.getIndex()];
label.getCaption().setValue(mylab);
}
</pre>
<p>Doesn´t work...</p>
<p>Then I tryed to change it with a text but nothing change... the label appears empty</p>
<pre class="_prettyXprint _lang-js">
function beforeDrawDataPointLabel( dph, label, icsc )
{
label.getCaption().setValue("XX");
}
</pre>
<p>Some idea?</p>
<p> </p>
<p>Thaks!</p>
Find more posts tagged with
Comments
Clement Wong
<p>You want the label on the axis changed so instead of your code that's the beforeDrawDataPointLabel event, move it to the beforeDrawAxisLabel event instead.</p>
<p> </p>
<p> </p>
<p>You'll need to check which Axis you're changing so that's why there's an IF statement:</p>
<pre class="_prettyXprint">
function beforeDrawAxisLabel( axis, label, icsc )
{
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
//LINEAR_LITERAL
//LOGARITHMIC_LITERAL
//TEXT_LITERAL
//DATE_TIME_LITERAL
if (axis.getType() == AxisType.DATE_TIME_LITERAL) {
var mylab = listVentas[dph.getIndex()];
//var mylab = "hi";
label.getCaption().setValue(mylab);
}
}
</pre>
Ilija Angulovich
<p>Thx for the aswer Clement,</p>
<p> </p>
<p>The problem with your code is that in <span>beforeDrawAxisLabel i don´t have dph to see what is the index that corresponds in the data´s array..</span></p>
<p> </p>
<p><span>Somo idea?</span></p>
<p> </p>
<p><span>Thx so much.</span></p>
Ilija Angulovich
<p>Ok I fix it! THX!</p>
<p> </p>
<p>Final code:</p>
<pre class="_prettyXprint _lang-js">
/**
* Called before generation of chart model to GeneratedChartState.
*
*
@param
chart
* Chart
*
@param
icsc
* IChartScriptContext
*/
var index = null;
var maxSerie = null;
var counter = 0;
var listVentas;
function beforeGeneration( chart, icsc ) {
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
sd = chart.getAxes().get(0).getAssociatedAxes().get(0).getSeriesDefinitions().get(1);
rs = sd.getRunTimeSeries();
//Inicio contador del total de los valores para la linea de la derecha
var contTotal = 0 ;
var max = 0;
listVentas = rs.get(0).getDataSet().getValues();
for (var i = 0; i < listVentas.length; i++){
contTotal = contTotal + listVentas[i];
if (listVentas[i] > max){
max = listVentas[i];
maxSerie = max;
index = i;
}
}
}
/**
* Called before drawing each datapoint graphical representation or marker.
*
*
@param
dph
* DataPointHints
*
@param
fill
* Fill
*
@param
icsc
* IChartScriptContext
*/
function beforeDrawDataPoint(dph, fill, icsc)
{
temp = dph.getOrthogonalValue();
tempF = maxSerie;
if(dph.getIndex() == index && temp == tempF && counter == 0) {
fill.set(185, 206, 149);
counter += 1;
}
}
var cnt = 0;
function beforeDrawAxisLabel( axis, label, icsc )
{
//LINEAR_LITERAL
//LOGARITHMIC_LITERAL
//TEXT_LITERAL
//DATE_TIME_LITERAL
if (axis.getType() == AxisType.TEXT_LITERAL) {
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
var mylab = listVentas[cnt];
label.getCaption().setValue( parseInt(mylab));
cnt++;
}
}
</pre>