dashed line in Jfreechart - jfreechart

Does anybody knows how to draw a vertical dashed line in Jfreechart at some given coordinates ?
Thanks

Example 5 shows a series of dashed lines for a chart. Set your stroke thus:
plot.getRenderer().setSeriesStroke(
0,
new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {6.0f, 6.0f}, 0.0f
)
and you'll need to set your dataset to simply reference the coordinates of your vertical line.

Related

How to properly create outline around image using RGB values?

I have an image that I import into Octave 5.2, and I would like to create an outline all the way around the image array using RGB values.
I'm having trouble inserting the RGB values back into the array correctly, inserting / generating the two rows at top, two columns on the left, two columns on the right, and two rows on the bottom all the way around the image / converted double array.
Example of original image:
Example of the image I'm trying to get when done:
My logic was:
To convert the image to a double array so I can do math / insert the RGB values where I wanted them.
Insert the RGB values into the left, right, top, bottom of the array.
Convert the double array back to uint8 to export / view it as image.
My code so far:
pkg load image
img_fn=('https://i.imgur.com/KKxJaOy.png'); %original image
f=imread(img_fn);
[im_r im_c]=size(f);
size_min=min(im_r,im_c); %get minum size from row and col
f_double=double(f); %need to convert to double to do math functions on it
outline_left_of_box=repmat(255,[rows(f_double),2]); %Create left line array of outline red box
f_double_tmp_red(:,:,1)=[outline_left_of_box,f_double];%Create left line of outline red box
red_outline_right_of_box=repmat(255,[rows(f_double),2]); %Create right line array of outline red box
red_outline_top_of_box=repmat(255,[2,columns(f_double)]); %Create top line array of outline red box
red_outline_bottom_of_box=repmat(255,[2,columns(f_double)]); %Create bottom line array of outline red box
%convert back to image
red_outline_img=uint8(f_double);
imshow(red_outline_img); %used to show image in octave plot window
Please note: I'm converting the image array into a double because calculations will be done on the array to get the desired color box around the image, but I'm just trying to get the inserting RGB values into the array issue fixed first.
Maybe it's easier to simply paste the inner part of the input image onto some "background" image with the desired border color, like so:
pkg load image
% Read image, get dimensions, convert to double
f = imread('https://i.imgur.com/KKxJaOy.png');
[im_ro, im_co, im_ch] = size(f);
f_double = double(f);
% Set up width and color of border
bw = 2;
color = ones(1, 1, im_ch);
color(1, 1, :) = [255, 0, 0];
% Create image of same size as input with solid color, and paste inner part of input
red_outline_img = ones(im_ro, im_co, im_ch) .* color;
red_outline_img(bw+1:end-bw, bw+1:end-bw, :) = f_double(bw+1:end-bw, bw+1:end-bw, :);
red_outline_img = uint8(red_outline_img);
imshow(red_outline_img);
That'd be the output:
Another thing you could try is plot the lines as you suggest, which can be done very efficiently with some clever use of xlim/ylim, and then print the whole thing as an -RGBImage to get it back in image form.
The only caveat here though is that you will need to play with the formatting options to get what you're really after (e.g. in case you want higher or lower resolution), since you really are printing what's on your screen at this point.
E.g.
L = imread('leaf.png');
imshow(L)
hold on
plot( [xlim, fliplr(xlim);xlim, xlim], [ylim, ylim;fliplr(ylim), ylim], 'r', 'linewidth', 2 )
hold off
set( gca, 'position', [0, 0, 1, 1] );
set( gcf, 'paperposition', [0, 0, 1, 1] );
R = print( '-RGBImage' );
close
imshow(R); set( gcf, 'color', 'k'); axis off

How to change colour of specific points in ggtern

I am using ggtern to graph some RGB data, where each point refers to the colour % from red, green or blue.
I was wondering if it is possible to change the colour of specific plot points to match the actual colour which they are representing?
I have tried using some ggplot2 commands but it doesn't work.
This is what I am using now:
library(ggplot2)
library(ggtern)
library(readxl)
Image9 <- read_excel("~/PhD/Image9.xlsx")
View(Image9)
ggtern(data=Image9, aes(x = Blue, y = Red, z= Green )) + geom_point( size=2,
shape=16, color="black") + theme_rgbw() + theme_hidegrid_major() +
theme_hidetitles()+ theme_rotate(degrees = 120) +
geom_text(aes(label=Colour), size=3, color="black", hjust=0, vjust=0)
Using this command I can plot the data as a colour intensity percentage in Red, Green and Blue and label the points so that I can map them back to the original image
1; representative image of plot.
Ideally I would like to plot each point as the same shade of color which they represent within the color space, I don't know if this is possible with this package.
Any suggestions would be greatly appreciated.

Highcharts - How to specify dimensions of rectangles

I working with highcharts in angularjs and I want to change the background like in the picture. Also, I want to be able to specify dimentions of rectangles
UPDATE
The problem is when I give the parameters to draw my rectangles, it's affecting all the div and what I want is to draw the rectangles on my chart surface only. The problem is because of "this" which I'm using in my code and I want now to replace it with chart.
You can use the renderer to draw arbritary squares on a chart. You can also use the Axis function toPixels to convert values to pixels. I have a function that takes x and y values and draws a square. If you butted those squares together you could have your regions.
var drawSquare = function(x1,x2,y1,y2,color) {
x1 = chart.xAxis[0].toPixels(x1);
x2 = chart.xAxis[0].toPixels(x2);
y1 = chart.yAxis[0].toPixels(y1);
y2 = chart.yAxis[0].toPixels(y2);
var width = x2 - x1;
var height = y1 - y2;
chart.renderer.rect(x1,y2,width, height, 0)
.attr({
fill: color,
zIndex: 0
})
.add();
};
drawSquare(0,40,0,35,'rgba(129,184,222,.5)');
drawSquare(40,100,0,35,'rgba(255,223,134,.5)');
drawSquare(0,40,35,150,'rgba(130,215,169,.5)');
drawSquare(40,100,35,150,'rgba(183,153,206,.5)');
http://jsfiddle.net/Lh74L8vu/1/

JfreeChart Axis custom precision or range

I am trying to plot a XYPlot using JfreeChart. My X axis has number or client say 30, 50 ,70
and Y axis has cache hit ratio( Value of which sometime varies by 0.01) When i set AutoRange the y axis show range as 0.1 0.2 0.3..... 1.0. So sometimes my plot is nearly straight line since it varies by such a small factor.
I have tried this code
JFreeChart chart = ChartFactory.createXYLineChart(
"Effect of Number of Clients", // Title
"Number of Clients", // x-axis Label
"Cache Hit Ratio", // y-axis Label
datasetLRU, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
true, // Use tooltips
false // Configure chart to generate URLs?
);
chart.setBackgroundPaint(Color.white);
plot= chart.getXYPlot();
plot.setBackgroundPaint(Color.black);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
final ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(false);
final NumberAxis axis2 = new NumberAxis("Axis 2");
axis2.setAutoRangeIncludesZero(false);
axis2.setTickUnit(new NumberTickUnit(0.01));
plot.setDataset(1, datasetMARS);
plot.setRenderer(1, new StandardXYItemRenderer());
plot.setDataset(2, datasetNEW);
plot.setRenderer(2, new StandardXYItemRenderer());
So Can any one help in setting Y axis range as 0.01 0.02 0.03 .... 0.98 0.99 1.00
Thanks
Your code doesn't configure the range axis because you create axis2 but you never assign it. When using auto range you can also configure the minium size of an auto ranged axis (method setAutoRangeMinimumSize(double)).
Please try the following source code part:
final NumberAxis axis2 = plot.getRangeAxis();
axis2.setAutoRange(true);
axis2.setAutoRangeIncludesZero(false);
axis2.setAutoRangeMinimumSize(0.001);
axis2.setTickUnit(new NumberTickUnit(0.01));

Bold x axis values in jfreechart

How can I bold the x and y axis values in jfreechart?
Have you tried one of those:
yourAxis.setTickLabelFont(new Font("Arial", Font.BOLD, 10)); //to define a specific font
or
Font bold = yourAxis.getTickLabelFont().deriveFont(Font.BOLD);
yourAxis.setTickLabelFont(bold); //to use the existing font, but bold

Resources