PDA

View Full Version : Charts 3.0 how to create Dynamic markers or marker customizations.



hrishirise
27 Jan 2012, 5:24 PM
Hi,
I am working on Line charts. I want to be able to customize look and feel of each Marker based on the data type.

How do i do that.

Currently, the markers are set for entire chart. like this.
Sprite marker = Primitives.diamond(0, 0, 2);
marker.setFill(RGB.GREEN);
series.setMarkerConfig(marker);


Please let me know

BrendanC
30 Jan 2012, 11:40 AM
You could use the setRenderer() method on line series. This gives you access to each marker sprite, along with its corresponding store index, as it is drawn.

hrishirise
30 Jan 2012, 12:16 PM
Thanks Brendan,
That helps in step 1 for me.That works for changing Marker colors and attributes etc.
But, if i want to "replace" the marker and update it with something like Primitives.diamond or a new customized marker its not working. Its just changing colors of existing Marker. I am using "setComponent" method to set a complete new component style.

series.setRenderer(new SeriesRenderer<XXX>() {
@Override
public void spriteRenderer(Sprite sprite, int index, ListStore<XXX> store) {
if(store.get(index).getEvents()!=null){
DrawComponent dc = new DrawComponent();
Sprite marker = Primitives.diamond(0, 0, 12);
marker.setFill(RGB.GREEN);
dc.addSprite(marker);
sprite.setComponent(component);
} else {
DrawComponent dc = new DrawComponent();
Sprite marker = Primitives.circle(0, 0, 12);
marker.setFill(RGB.BLUE);
dc.addSprite(marker);
sprite.setComponent(component);
}
}
});


Please do let me know, if you see anything wrong or any way i can do this.

Thanks,
Hrishi

BrendanC
22 Feb 2012, 3:28 PM
Unfortunately you cannot change the sprite type in series renderers for performance reasons. However PathSprite does have a copy constructor for all sprite types, which you could use on the circle primitive. For example:


final PathSprite diamond = Primitives.diamond(0,0,12);
final PathSprite circle = new PathSprite(Primitives.circle(0,0,12);
series.setRenderer(new SeriesRenderer<XXX>() {
@Override
public void spriteRenderer(Sprite sprite, int index, ListStore<XXX> store) {
if(store.get(index).getEvents()!=null){
sprite.setCommands(diamond.getCommands);
sprite.setFill(RGB.GREEN);
} else {
sprite.setCommands(circle.getCommands);
sprite.setFill(RGB.GREEN);
}
}
});

Also keep in mind you can also use Sprites that are not in the Primitives class for markers.