JFreechart: Preventing truncation in bubble charts - jfreechart

I'm writing an automatic report generator that visualizes three-way evaluations as coordinate graphics, where the circle size expresses the third value as a kind of virtual Z coordinate. It works fine, but when a top-rated item is displayed near the edge, its circle may be cut off, like this:
I'd like to extend the chart so that the entire circle is drawn, but the axes shouldn't get labels above 10 (the evaluation allowed choices 1-10, and it would be misleading to pretend that 11 was an option). How can I extend the ValueAxis farther up and right, but without more ticks? Or how can I extend the entire chart space, but without extending the X and Y axes?

You can try passing a larger percentage to setUpperMargin(); this fragment specifies 20%.
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
NumberAxis domain = (NumberAxis) xyplot.getDomainAxis();
domain.setUpperMargin(1/5d);
NumberAxis range = (NumberAxis) xyplot.getRangeAxis();
range.setUpperMargin(1/5d);

Related

How to move the x-axis labels on a datetime scale further from the edges?

I have this chart: https://playground.anychart.com/D7okDBpO/2
I would like the plot and x-axis labels to have some padding from the left and right edges (one of the reasons is that the last x-label is not even fully visible right now), similarly to how a chart with ordinal scale is rendered. For the plot I managed to do this with:
series.left(30);
series.right(30);
But I can't find a solution for the x labels. What I've tried:
// This doesn't work because it moves both first and last label
chart.xAxis().labels().offsetX(-30);
// This doesn't work because it moves all the labels, even the ones in the middle
chart.xAxis().labels().padding().left(50);
are you looking for this setting:
chart.left(20);
chart.right(20);
https://playground.anychart.com/miB1VAbq ?

OxyPlot WPF Muliple LinearBarSeries with same X-Axis Values

I currently have the need to be able to display multiple bars that may have the same X-Axis value. I used the WPF LinearBarSeries example in the source code.
The issue I am having is if the series with the smaller Y value is selected first, the series with the bigger Y value hides the smaller one. If I select the series with the bigger Y value first and then the smaller Y value, they both are displayed.
I am putting a small border around my bars to make them more readable.
Bigger First
Smaller First
Admittedly, I'm not an expert with OxyPlot and I haven't done a whole lot of charting in the past. Is there a better approach I should be taking? Maybe a different Series to use?
I did not find the way to display LinearBarSeries side by side either. I finally used the RectangleBarSeries where the bar is defined between two points x,y, and so you can manually define an offset between them.
var serie = new RectangleBarSeries { Title = "Example"};
serie.Items.Add(new RectangleBarItem(x1, 0, x2, y2));

Grid image values to 2D array

I have a grid like the image below which I want to put in an array in this format:
;x = wall(black cells and grey boxes), s= start (red circle), g = goal(blue circle), 0 = available path(everything else)
$data[5][5] = [["x","x","x","x","x"], _
["x","s","0","x","x"], _
["x","x","0","x","x"], _
["x","x","0","g","x"], _
["x","x","x","x","x"]]
I thought I could use the colors but I'm not sure how.
looks like you have the view with fixed angles
create function that converts screen position to grid position and back. It should be easy just 2x linear interpolation. if the camera pan is not with cell based step then you need the corner point of grid lines and use that as a start point ...
for example something like this (hope I measured the pixels correctly):
x = 236 + (+(u-uh)-(v-vh))*60;
y = 133 + (-(u-uh)-(v-vh))*30;
60,30is the cell size in x,y
(236,133) is position of center of mid cell (uh,vh) in pixels
uh,vh are coordinates in your grid of center cell
add the views pan offset to (uv,hv) or (236,133) now just compute the also the reverse transform from this (u=?,v=?). Do not forget that the map is not rectangle! It is something like this:
0000x0000,
000xxx000,
00xxxxx00,
0xxxxxxx0,
xxxxxxxxx,
0xxxxxxx0,
00xxxxx00,
000xxx000,
0000x0000,
create a set of images of all objects that you can encounter
this can be done on the run, each time you do not found a match add cell to item list as new object type.
loop through all grid cell locations and compare to object types
for pixel precise rendered images you can compare directly pixels 1:1 if that is not the case the you need to compare objects more robustly. But to make a valid algorithm we need to see all the types of object you can encounter usually you can compare:
average,min and max colors, histograms,
aspect ratio,...
FFT/DCT
center of mass position,density, and more
do not forget to mask comparison to area of cell only to not include the neighboring cells on corners of bounding rectangle
[Notes]
Can not be more specific without further info

JFreeChart: Logarithmic Axis Tick Labels missing

I am using JFreeChart to make XYLineCharts with a Logarithmic y-axis but am facing an issue that I am unable to resolve.
My x, y values are very low in some cases (in one such case, the y-axis values for the dataset range between 4.5e-8 to 1.7). I plot these values on a XYLineChart using a Logarithmic Axis for the y-axis (and using LogAxis.createLogTickUnits(Locale.ENGLISH) and .setExpTickLabelsFlag(true) on the y-axis to create the exponential tick units). I set my range's bounds from 4.5e-8 to 1.7 and can see the points plotted clearly but there are no tick labels visible for the y-axis !
I was earlier having this issue while zooming into the charts but I have fixed the zoom & AutoZoom by over-riding those methods.
My current LogarithmicAxis works well for most of my x, y datasets but in a few cases, the y-axis is plotted but does not show any Tick Labels on it, despite my creating them & setting their visibility to true.
If anyone has any suggestions on how to fix this & ensure that the Tick Labels are visible no matter what the y-axis values may be, please let me know soon as I need to get this done ASAP.
Thanks.

simple plot algorithm with autoscale

I need to implement a simple plotting component in C#(WPF to be more precise). What i have is a collection of data samples containing time (X axis) and a value (both double types).
I have a drawing canvas of a fixed size (Width x Height) and a DrawLine method/function that can draw on it. The problem I am facing now is how do I draw the plot so that it is autoscaled? In other words how do I map the samples I have to actual pixels on my Width x Height canvas?
One hacky method that may work is to use a Viewbox control. This control will scale the rendering of its content to fit the size available. However, this might lead to your lines and labels looking too thick or thin.
The more sensible method that you're probably after, though, is how to work out at what scale to draw your graph at in the first place. To do that, work out the range of values on a given axis (for example, your Y-axis value might range from 0 to 100). Work out the available drawing space on that axis (for example, your canvas might have 400 pixels of height). Your Y-axis "scale factor" when drawing the graph would be <available space> / <data range> - or, in this case, 4.
Your canvas' coordinates start from zero in the top-left so, to calculate the Y-position for a given data point, you would calculate like this:
double availableSpace = 400.0; // the size of your canvas
double dataRange = 100.0; // the range of your values
double scaleFactor = availableSpace / dataRange;
double currentValue = 42.0; // the value we're trying to plot
double plottableY = availableSpace - (currentValue * scaleFactor); // the position on screen to draw at
The value of plottableY is the y-coordinate that you would use to draw this point on the canvas.
(Obviously this code would need to be spread out across your drawing method so you're not recalculating all of the values for each point, but it demonstrates the math).

Resources