How to set background of graph marker line text programmaly?

Options
Frenkys
edited February 11, 2022 in Analytics #1

I use this function to set graph marker line:

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);

var chart = icsc.getChartInstance();
var yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);
var ok_value = 40;

ok_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(ok_value));
ok_ml.getLabel().getCaption().setValue("Test value " + ok_value);
ok_ml.getLabel().getCaption().getFont().setSize(10);
ok_ml.getLabel().getCaption().getFont().setBold(true);
ok_ml.getLabel().getCaption().getFont().setRotation(90);
//ok_ml.getLabel().getCaption().getFont().setBackground(0,255,0);
ok_ml.getLineAttributes().getColor().set(255,0,0);
ok_ml.getLineAttributes().setThickness(3);
}

How to set marker line text background color?
"ok_ml.getLabel().getCaption().getFont().setBackground(0,255,0);" return this error:
"Cannot find function setBackground in object org.eclipse.birt.chart.model.attribute.impl.FontDefinitionImpl@..."
Thanks

Comments

  • I don't know if this is a textbook solution, but I will count it as an achievement unlocked. I copied your code into the chart script in the attached report and added the code at the bottom to change the fill color. Please test the code before using it in production.

    Warning No formatter is installed for the format ipb