OverlaidXYPlotDemo1 : Changing Series Color - java

I have managed to change the color of the bars in the OverlaidXYPlotDemo1, with :
XYItemRenderer xir = plot.getRenderer();
xir.setSeriesPaint(0, Color.BLUE);
However, I can´t change the color of the second series with
xir.setSeriesPaint(1, Color.GREY);
so I´m probably missing something. Any hints?

I figured it out. The correct way to do this, is using the renderers:
renderer1.setSeriesPaint(0, Color.YELLOW);
renderer2.setSeriesPaint(0, Color.GREY);

Related

Custom icon is not centered

I am trying to add a marker on my site. Everything is working but I saw that marker always is slightly shifted in relation to this where I clicked. Additionally this problem occur only when I try to add a custom icon. All is correct when I use the default icon marker.
Part of code responsible for adding marker on my site:
lastMarker = new google.maps.Marker(
position : location,
map: mapDefault,
draggable : true,
icon : {
path : fontawesome.markers.MAP_MARKER,
scale : 0.75,
strokeWeight : 0.2,
strokeColor : 'black',
strokeOpacity : 1,
fillColor : $('#quest_marker'+
currentPageButton).attr('data-
value'),
fillOpacity : 1,}
});
As a result of this I received something like this:
When I try to add default icon then is correct:
What causes this problem, and how to solve it.
You can use icon's anchor option
For example;
If your png size 32,32, then you adjust icon's anchor like this:
icon:{
...
anchor: new google.maps.Point(16,32)
}
So, you can point tip of your icon.

How to create shapes on a JFreeChart line chart?

I would like to have shapes (small squares) that mark data points in the line chart that I am creating with ChartFactory.createLineChart().
It should look something like this (this image was not created with JFreeChart):
I have followed the description here, however, they don't appear for me. This is what the output from my JFreeChart software looks like:
My code is:
JFreeChart lineChart = ChartFactory.createLineChart(...);
CategoryPlot plot = (CategoryPlot) lineChart.getPlot();
plot.getRenderer().setBaseShape(
new Rectangle2D.Double(-20.0, -20.0, 40.0, 40.0));
I also tried using setSeriesShape instead of setBaseShape for all the series I'm plotting, it didn't make any difference either.
What am I doing wrong?
Given a reference to the renderer,
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
Invoke setBaseShapesVisible() to enable the shapes provided by your chosen DrawingSupplier.
renderer.setBaseShapesVisible(true);
To change the appearance, pass a custom Shape to setSeriesShape() for the desired series.
renderer.setSeriesShape(0, new Ellipse2D.Double(-3d, -3d, 6d, 6d));
From JFreechart 1.5.0
LineAndShapeRenderer renderer = (LineAndShapeRenderer) lineChart.getCategoryPlot().getRenderer();
renderer.setDefaultShapesVisible(true);

JFreeChart Smudging of lines in Candlestick Chart

This has reference to JFreeChart rendering of candlestick charts. Below is the code fragment that generates a candle stick chart with JFreeChart.
This code has been tested and has been working for a long time. However, the version of JFreeChart was changed from 1.0.17 to 1.0.19 and the candlestick chart generated with 1.0.19 is showing smudging of the candle objects/lines. When I changed the library back to 1.0.17, the candlestick objects/lines once again becomes clear.
The images with both the libraries are provided below.
I have tried to find the cause of this and have been unsuccessful as yet. Now, the question is, since the code is tested and possibly does not have any error (at least what I can figure or am I missing something?), is the issue with the library? Have anyone faced this problem and has an work around
I shall be rather grateful, if someone has found the reason/solution to this and shared the same.
Please use MS Paint to view the images.
try{
chart=ChartFactory.createCandlestickChart("Candlestick Chart", "Date", "EOD Closing Price", (OHLCDataset)dataset, true);
plot=(XYPlot)chart.getPlot();
CandlestickRenderer renderer=new Chart_CandlestickRenderer();//(CandlestickRenderer)plot.getRenderer();
renderer.setSeriesPaint(0, Color.BLACK);
renderer.setUpPaint(Color.WHITE);
renderer.setDownPaint(Color.BLACK);
//HighLowItemLabelGenerator candleTooltipGenerator=new HighLowItemLabelGenerator(new SimpleDateFormat("dd-MMM-yyyy"), new DecimalFormat());
XYToolTipGenerator candleTooltipGenerator=Chart_TooltipProvider.getOHLCTooltipGenerator();
renderer.setBaseToolTipGenerator(candleTooltipGenerator);
plot.setRenderer(0,renderer);
//Organize the data to draw Fibbonacci retracements with highs and lows
DefaultOHLCDataset ohlcDataset=(DefaultOHLCDataset)dataset;
int dataCount=ohlcDataset.getItemCount(0);
data=new double[dataCount*2];//for each data item we shall get 2 values, high and low
for(int i=0;i<dataCount;i++){
//for each i 2 data values need to be put into the array and adjust the index accordingly
data[i*2]=ohlcDataset.getHighValue(0, i);
data[i*2+1]=ohlcDataset.getLowValue(0, i);
}//for closing
//If there is only the candlestick to be drawn, return, as the job has been done, draw the Fibonnaci and return
if(indicators.length==1){
this.drawFibonnaciRetracement(data, plot);
retVal=true;
return retVal;
}//if closing
}catch(Exception e){e.printStackTrace();return retVal;}
Try setting setAntiAlias of the JFreeChart to false.
JFreeChart chart = ChartFactory.createCandlestickChart(...);
chart.setAntiAlias(false);

JFreeChart BarChart -> NO gradient

my bar chart is always drawn with a gradient color by default. I just want a simple color without any styled effects.
Can anyone help ?
Code:
final JFreeChart chart = ChartFactory.createBarChart(
"", // chart title
xLabel, // domain axis label
yLabel, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
false, // tooltips?
false // URLs?
);
final CategoryPlot plot = chart.getCategoryPlot();
// SOMETHING HAS TO BE DONE HERE
showChart(chart); // Simply shows the chart in a new window
Thanks
The problem lies in the BarPainter you are using. The JFreeChart version 1.0.13 default is to use GradientBarPainter which adds a metallic-ish look to the bar. If you want the "old" look the solution is to use the StandardBarPainter.
final CategoryPlot plot = chart.getCategoryPlot();
((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());
That should do it.
Alternatively, if you want use JFreeChart's BarRenderer, you could force it to use the StandardBarPainter by calling the static method setDefaultBarPainter() before initializing your renderer.
final CategoryPlot plot = chart.getCategoryPlot();
BarRenderer.setDefaultBarPainter(new StandardBarPainter());
((BarRenderer) plot.getRenderer()).setBarPainter(new BarPainter());
If you want more control of the chart you can always build it from the ground up instead of using ChartFactory, but that does require a lot extra code.
Before you create the chart from ChartFactory you can set the chart theme:
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
The default is the JFreeTheme which adds the gradient. The following themes are available:
ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());
The source code for an older version of org.jfree.chart.demo.BarChartDemo1 shows how to set the series colors. Just specify plain colors instead of gradients.
renderer.setSeriesPaint(0, Color.red);
renderer.setSeriesPaint(1, Color.green);
renderer.setSeriesPaint(2, Color.blue);
Correction: The key to #Jes's helpful answer may be found in the initialization of defaultBarPainter in BarRenderer.

How to customize series fill in area chart via BIRT chart API?

I am trying to create a gradient fill for a series in an area chart that I am building through the BIRT chart API, but the book "Integrating and Extending BIRT" and the Interwebs seem curiously silent about how to get it to work. It seems no matter what I do, I always get a flat color from the default palette. I've tried using SeriesDefinition.getSeriesPalette().update(Gradient) and even creating my own Palette with the gradient fill in it and setting that on the SeriesDefinition, but to no avail. I've also noticed that if I do not perform a shift() on the Palette, even if it's shift(0), which the Javadocs claim will do nothing, I get NullPointerException when I try to generate the chart:
Caused by: java.lang.NullPointerException
at org.eclipse.birt.chart.render.Area.renderDataPoints(Area.java:521)
at org.eclipse.birt.chart.render.Line.renderSeries(Line.java:570)
at org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRenderer.java:2181)
at org.eclipse.birt.chart.render.AxesRenderer.render(AxesRenderer.java:314)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1368)
... 108 more
Here's the latest (non-working) code that I've tried:
Gradient gradient = FillUtil.createDefaultGradient(BirtReportBuilder.COLOR_WHITE);
gradient.setStartColor(ColorDefinitionImpl.WHITE());
gradient.setEndColor(ColorDefinitionImpl.create(76, 116, 131));
gradient.setDirection(90);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getQuery().setDefinition("\"Quantity\"");
Palette pal = PaletteImpl.create(gradient);
pal.shift(0);
sdY.setSeriesPalette(pal);
sdY.getSeries().add(as1);
yAxisPrimary.getSeriesDefinitions().add(sdY);
So what's the magic incantation to get the BIRT charting API to use my Gradient as the area fill?
This code works for me, I get a ugly coloured serie...
sdY.getSeriesPalette().update(GradientImpl.create(ColorDefinitionImpl.create(255,255,255), ColorDefinitionImpl.create(200,0,0,150), 90, false));
Hope it will help you ;p

Categories