jfree / jcommon Goto Github PK
View Code? Open in Web Editor NEWJCommon class library (used by JFreeChart 1.0.x)
License: GNU Lesser General Public License v2.1
JCommon class library (used by JFreeChart 1.0.x)
License: GNU Lesser General Public License v2.1
Hi, thanks for the chart component and associated jcommon library!
I have a question/possible addition. I am trying to create a specialised form of scatter chart, where one of the series represents the variation in load along a linear distance (e.g. variation of mass at different points on a bridge). I want to show that load series as bars - in effect, a bar graph but with real x-values instead of just categories. The x-axis therefore is distance, the y-axis is mass.
My approach (which may not be the right one anyway) was to try to override getItemShape thus:
xyPlot.setRenderer(new XYLineAndShapeRenderer(false, true)
{
@Override
public Shape getItemShape(int aSeries, int anItem)
{
Shape itemShape = super.getItemShape(aSeries, anItem);
String seriesName = xyDataset.getSeriesKey(aSeries).toString();
if (seriesName.equalsIgnoreCase("Load")
{
double x = xyDataset.getXValue(aSeries,anItem);
double y = xyDataset.getYValue(aSeries,anItem);
//NEW SHAPE HERE
}
return itemShape;
}
});
For the new shape, I have tried using:
itemShape = ShapeUtilities.createLineRegion(new Line2D.Double(x,y,x,0),barWidth);
However, this seems to have some sort of x-scaling issue; the bars drift further and further from where they should be the further to the right you go. Furthermore, the heights of the bars aren't correct - I think there must be some sort of scaling factor to be applied?
I then tried adding my own shape, by adding this code in ShapeUtilities:
/**
* Creates a vertical bar
*
* @param y the height of the bar (usually this is the y value of the point)
* @param w the width of the bar.
*
* @return A bar shape.
*/
public static Shape createBar(double y, float w)
{
GeneralPath p0 = new GeneralPath();
p0.moveTo(-w/2, 0);
p0.lineTo(w/2, 0);
p0.lineTo(w/2, y);
p0.lineTo(-w/2, y);
p0.closePath();
return p0;
}
I used it thus:
itemShape = ShapeUtilities.createBar(y, barWidth);
However, again, there seems to be some sort of scaling/transformation I need to do to get the desired result.
In summary, is there any simple way of achieving what I want? And am I nearly there with what I've got so far, just can't see the scaling function I need to perform?
Thanks!
EDIT:
I've also tried:
itemShape = new Rectangle2D.Double(-barWidth/2.0F,0,barWidth/2.0F,y);
This gets the rectangles in the correct x-location, and the top of each one is at the correct y-location. But the bottom does not drop all the way down to the x-axis. So I'm nearly there - just need to know how to scale from dataset y-values to chart y-values... (if that's the case, I probably won't be needing to submit a pull request for a createBar in ShapeUtilities - though it still might be useful to someone!)
EDIT2:
I've now also tried:
ValueAxis yAxis = xyPlot.getRangeAxis();
RectangleEdge yAxisEdge = xyPlot.getRangeAxisEdge();
Rectangle2D area = chartPanel.getChartRenderingInfo().getPlotInfo().getPlotArea();
double plotY = yAxis.valueToJava2D(y, area, yAxisEdge);
itemShape = new Rectangle2D.Double(-barWidth,0,barWidth,plotY);
However, although this may well work in some cases, it doesn't work when used inside an overridden GetItemShape, because at that point the chartPanel is not yet visible, so doesn't yet have an area!
So, I created a completely separate renderer:
private XYLineAndShapeRenderer myXYLineAndShapeRenderer = new XYLineAndShapeRenderer(false,true)
{
@Override
public Shape getItemShape(int aSeries, int anItem)
{
//STUFF IN HERE
}
};
along with
xyPlot.setRenderer(myXYLineAndShapeRenderer);
...in the chart creation code, hoping that the new renderer would get called when the chart gets painted. But it doesn't - it seems an overridden renderer only gets called if it's added directly using xyPlot.setRenderer(new XYLineAndShapeRenderer(false, true){...}
as per the first block of code I showed. And then only if it doesn't need to access chartPanel!
from https://sourceforge.net/p/jfreechart/bugs/1142/
"In org.jfree.text.TextUtilites I found in the method "public static void drawRotatedString(String text, Graphics2d g2, float textX, float textY, double angle, float rotateX, float rotateY)" a bug:
in the code fragment
if (angle == 0.0) {
drawAlignedString(text, g2, textY, textY, TextAnchor.BASELINE_LEFT);
return;
}
Should the method not called like this (textX was not used):
drawAlignedString(text, g2, textX, textY, TextAnchor.BASELINE_LEFT);"
Hi!
I'm packaging jcommon/jfreechart for Fedora and it would be helpful if released versions (as available on maven central) would get tagged. This simplifies generating a source tarball. In fact, I think github can be used to get a source tarball from a tag via: https://github.com/jfree/jcommon/archive/{tag}.zip
Thanks,
Severin
I found this library by reading the "Clean Code" book which has a chapter on refactoring SerialDate class.
Were those changes rejected because of being backward incompatible or for some other reason?
What about small bug fixes which the book highlighted, like in stringToMonthCode() which does not return -1 for the cases when the input is a string with a number, i.e. "12345" (it simply returns the parsed number, i.e. 12345 in this case).
JDK-4312117 - Drawing with AffineTransform widens text has been fixed since JDK1.5
jcommon requires 1.6 - therefore all coding related to this workaround can be removed
e.g.
isUseDrawRotatedStringWorkaround
setUseDrawRotatedStringWorkaround
both methods starts with declaring width and height as follows
int height = ins.top + ins.bottom;
int width = ins.left + ins.right;
and adding the insets again in the return statement
return new Dimension(width + ins.left + ins.right,
height + ins.top + ins.bottom);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.