Hello,
I need to provide ability to dynamically change the behaviour of charts using Beanshell. I have been looking at Beanshell site but couldn't get any examples.
Here is what I am trying to achieve.
In my dashboard application, I set the basic properities of the chart but need to do the following
"
BarRenderer3D r = (BarRenderer3D) plot.getRenderer();
r.setDrawBarOutline(true);
GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.BLUE,
0.0f, 300.0f, new Color(0,0,100,100));
GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, new Color(0,0,230,200),
0.0f, 300.0f, new Color(204,204,255,200));
r.setSeriesPaint(0,gp0);
r.setSeriesPaint(1,gp1);
"
I don't want to compile the above code in the application but leave it outside as a customizable source by the end-user. The only thing the application should pass is the "plot" variable and then rest of the renderer modifications should be done inside the Beanshell script.
I just started looking into Beanshell and got excited about the extensibility but don't know how to do it.
So far I have tried the the following and it works ....
CategoryPlot plot = pChart.getCategoryPlot();
try
{
Interpreter i = new Interpreter(); // Construct an interpreter
i.set("plot",plot);
i.eval(renderStr);
i.set("barRenderer",(BarRenderer3D)plot.getRenderer());
i.set("gp0",new GradientPaint(0.0f, 0.0f, Color.BLUE,
0.0f, 300.0f, new Color(0,0,100,100)));
i.eval("barRenderer.setSeriesPaint(0, gp0)");
}
catch (Exception ex)
{
ex.printStackTrace();
}
But I would prefer to do something like
i.eval("BarRenderer3D barRenderer = BarRenderer3D)plot.getRenderer();
All in one string, rather than setting the variable.
Is the above possible?
If I use the beanshell source() function, will I be able to achieve the above through a string rather than sourcing it through a "bsh" file?
Thanks a lot
Nilesh