This is a simple UI I made to learn the charts API in JavaFX. The AreaChart looks great however, I was wondering if it is possible to hide the tiny dots that signify the plotted values ?
The reason is that as the dots come closer, when the value of X axis increases, they become smaller and harder to comprehend. Sometimes they overlap. In such a situation, the graph would be more legible without the dots.
There is a method to hide the dots (or any other graphical representation of a x/y point).
final LineChart<Number,Number> lineChart =
new LineChart<Number,Number>(xAxis,yAxis);
//here be code...
lineChart.setCreateSymbols(false); //hide dots
Call setNode(...) on the XYChart.Data objects and pass in something invisible.
For example:
XYChart.Data data = new XYChart.Data(x,y);
Rectangle rect = new Rectangle(0, 0);
rect.setVisible(false);
data.setNode(rect);
Related
I'm programming a Strategy RPG using LibGDX, and Tiled as a map editor. I am loading the Tiled map with the Asset Manager and right now I don't have a Texture Atlas (I'm not quite sure yes which will be my definitive textures).
If you are familiar with Strategy RPG games, you should know that when you want to move a character, the cells where you can move it change color. That's what I'm trying to do.
But before figuring that, I'm trying to click a cell and change it's color by changing the texture of the upper layer of that cell, with the following code:
TiledMapTileLayer.Cell selectedCell = new TiledMapTileLayer.Cell();
selectedCell.setTile(selectedTileSet.getTile(0));
StaticTiledMapTile selectedTile = new StaticTiledMapTile(selectedSpriteRegion);
selectedCell.setTile(selectedTile);
selectedTileLayer.setCell((int) Math.floor(screenX / 32), (int) Math.floor((viewport.getScreenHeight() - screenY / 32)), selectedCell);
That code is inside a TouchDown inside a Screen, to be called every time I touch a part of the Screen.
The layer I use is one I set specifically for the highlighted tiles and it is above the rest of the layers in my code, except for the one that has the characters.
Thanks in advance!
I found the error.
Here is the new code:
TiledMapTileLayer.Cell selectedCell = new TiledMapTileLayer.Cell();
selectedCell.setTile(selectedTileSet.getTile(1765));
StaticTiledMapTile selectedTile = new StaticTiledMapTile(selectedSpriteRegion);
selectedCell.setTile(selectedTile);
selectedTileLayer.setCell(screenX / 32, (viewport.getScreenHeight() - screenY) / 32, selectedCell);
So there were two errors. First that the id of the tile was wrong. I thought that because I had one tile, it would be zero, but no, it is 1765 (don't ask me why).
Also, I was setting the wrong cell since the formula I used was wrong. Math.floor wasn't necessary and I was dividing before subtracting in the Y position (can't believe I did that).
That's all! Hope this helps to someone with a similar error in the future!
I have static points on a map.
I use this code to draw them:
point = GeometryEngine.project(longitude, latitude, mapSR);
pointGraphic = new Graphic(point, symbol);
graphicsLayer.addGraphic(pointGraphic);
The point is drawed on the map.
Now I want to add a label to it - show under the drawn point it's longitude and latitude.
I can do it using text adding, but then when I resize the map, the text placement changes.
I want to put it like a label - let's say on the bottom right from the point.
I want it to be sensitive for zooming, and binded to the Point.
I read about dinamic labels, but it seems very complex for such a simple request.
How can I do this?
Thanks.
Individual graphics don't have labels, but you can create two graphics with the same geometry. Use your current symbol for one of them. For the other graphic, use a TextSymbol, calling setOffsetX(float) and setOffsetY(float) to place it the way you want.
i have the following picture and what i actually want to detect is the circles above the box with letter to the top left of each box. But the result is that it detects also some other circles. I have no idea why.
Image that I want to detect on:
http://imgur.com/8oKmhGp
This is what the result looks like:
http://imgur.com/qBw6YhK
As you can see it can find letters as circles sometimes and also the circles on the lego. Here is my code:
Mat source = Highgui.imread("testar.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(), source.cols(), source.type());
Imgproc.cvtColor(source, destination, Imgproc.COLOR_RGB2GRAY);
Imgproc.GaussianBlur(destination, destination, new Size(3,3),0,0);
Mat circles = new Mat();
Imgproc.HoughCircles(destination, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 20, 10, 20, 7, 13);
int radius;
Point pt;
for (int x = 0; x < circles.cols(); x++) {
double vCircle[] = circles.get(0,x);
if (vCircle == null)
break;
pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
radius = (int)Math.round(vCircle[2]);
// draw the found circle
Core.circle(destination, pt, radius, new Scalar(0,255,255), 3);
Core.circle(destination, pt, 3, new Scalar(255,255,255), 3);
}
Highgui.imwrite("foundCircles.jpg", destination);
Well, IMHO, the Hough Circle detection algorithm is working exactly the way it is supposed to be. It IS detecting circles.
However, it seems like you do not want to detect the circles lying outside the area of the mobile phone's screen.
A simple solution can be implemented if you somehow manage to lay your hands on the exact coordinates of the four corners of the phone (or the mobile screen).
You can use the Rect class to define a rectangular block:
Rect cropRect = new Rect(topLeft_X, topLeft_Y, widthOfRectangle, heightOfRectangle);
and then use this rectangle object to reproduce a new image matrix (from the original one) that contains only the desired area:
Mat croppedImage = new Mat(inputImg, cropRect);
Now, with the freshly cropped image by your side, you can have all the fun you want with the algorithm of Mr. Paul Hough.
Now, if for some reason, it turns out that you do not have any clue about how to get the coordinates of the four corners of the phone (i.e, the phone moves around whimsically), OR you're damn irritated with the Hough circle detection reporting the O's and S's as circles, then you may try seeking the help of any good OCR implementation to help ease your pain.
Since you're on Java, you may use Tess4J. Or, you may try tweaking this project to extricate the position of the characters in the mobile screen. (There are many other OCRs which might help, please refer to this website for an exhaustive list)
Once you have the exact position of the characters, you may try running the Hough Circle detection block in the vicinity of the top left corner of the characters only.
One word of caution though, OCRs tend to be a wee bit nasty and unwieldy in Java.
If you're still unhappy with the results (or if OCRs seem to interfere with you metabolism), there's one last approach which you may try.... Hough Line detection.
Detect the lines, from the polar coordinates of the lines, estimate the grid that forms the keypad of the phone and then go around with detecting circles on the top left corner of the grids.
How can I remove the y labels from a JFreeChart chart? I use a NumberAxis for my y axis.
I can't seem to find a simple method for this anywhere.
I would like something similar to the remove legend syntax:
// Remove the legend
chart.removeLegend();
Note that I do want to define the title in the NumberAxis:
NumberAxis axis1 = new NumberAxis("A random title");
I simply don't want it to show up in the final chart.
I think that you mean that you want to hide the tick labels for the Y axis, but still want to see the label for the axis itself. Am I correct?
You can do that with:
axis1.setTickLabelsVisible(false);
Okay, if you want to:
hide the label in the chart
but still have it in the NumberAxis
Then there is one solution, that isn't perfect either, that you could use. If you set the "attributed label" (a label with extra font markup attributes), it will draw the attributed label instead.
You can set it to a single space (a zero-length string doesn't work - the font rendering code doesn't allow that).
rangeAxis.setAttributedLabel(" ");
At least axis1.getLabel() will still return your old label, but that's the only benefit of this that I can see.
Otherwise, you can subclass NumberAxis and override the method drawLabel in the subclass to do nothing:
protected AxisState drawLabel(String label, Graphics2D g2,
Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge,
AxisState state) {
return state;
}
My best solution so far is:
axis1.setLabel(null);
But this is just overwriting the original label (so not really a good solution).
I've created a XYChart with numerical values different (for example temperatue with pressure) so I want to draw my own axeS just beside my chart. To do the following I've to unshow the YAxis, how should I do that ?
By using a trick: The Chart needs the Y Axis to remain in place so it knows where to render your content. You can, however, hide it. Hide the tick labels and set the axis' opacity to 0 using this code:
chart.getYAxis().setTickLabelsVisible(false);
chart.getYAxis().setOpacity(0);
The axis will still be there, but not shown.
I found that if I hid the chart using the following code:
chart.getXAxis().setTickLabelsVisible(false);
chart.getXAxis().setTickMarkVisible(false);
((Path)chart.getXAxis().lookup(".axis-minor-tick-mark")).setVisible(false);
Then I get about ~10 pixels less blank space on the bottom. IF the space was an issue for your application then you could use css offsets to correct it. This solution may have more predictable offsets.
SOLVED: I got this to work for sharing a common x-axis for two charts stacked vertically:
Create two charts, each with their own identical copy of the x-axis object, setting identical upper and lower bounds (optionally by binding).
Then hide the x-axis in the second chart like this:
chart = new LineChart<Number,Number>(xaxis2,yaxis2) {
{// hide xAxis in constructor, since not public
getChartChildren().remove(getXAxis());
// not getPlotChildren()
}
};
You'll want to set the widths of your y-axes to be the identical, e.g.
int w = 60;
yaxis.setMaxWidth(w);
yaxis.setMinWidth(w);
yaxis.setPrefWidth(w);
yaxis2.setMaxWidth(w);
yaxis2.setMinWidth(w);
yaxis2.setPrefWidth(w);