I am working at a project that requires a BarChart at the index page.
I want it to display underneath the bars, the labels set in the chart series, but it only will display the value set in the first chart series added to the chart model.
Here is my code:
vencidoMas90dias = new BarChartSeries();
vencido90dias = new BarChartSeries();
vencido60dias = new BarChartSeries();
vencido30dias = new BarChartSeries();
vence30dias = new BarChartSeries();
vence60dias = new BarChartSeries();
vence90dias = new BarChartSeries();
vencidoMas90dias.set(">90 días", v.getVencidoMasTresMeses());
vencido90dias.set("90 y 60 días", v.getVencidoTresMeses());
vencido60dias.set("60 y 30 días", v.getVencidoDosMeses());
vencido30dias.set("30 y 1 día", v.getVencidoMes());
vence30dias.set("1 a 30 días", v.getTreintaDias());
vence60dias.set("30 a 60 días", v.getSesentaDias());
vence90dias.set("60 a 90 días", v.getNoventaDias());
modelo.addSeries(vencidoMas90dias);
modelo.addSeries(vencido90dias);
modelo.addSeries(vencido60dias);
modelo.addSeries(vencido30dias);
modelo.addSeries(vence30dias);
modelo.addSeries(vence60dias);
modelo.addSeries(vence90dias);
But the chart is displaying only one label in the center bar, and I need to display the label for each bar.
Does anybody know what is wrong with this? I am using Primefaces 4.0, and the examples in the showcase seem to have some differences, and they are not very clear sometimes.
Thanks in advance
You want to draw BarChart, why add BarChartSeries? I think you could setup BarChart with the following code:
CartesianChart modelo = new CartesianChart();
modelo.setLabel("Label");
ChartSeries s = ChartSeries();
s.set(">90 días", v.getVencidoMasTresMeses());
s.set("90 y 60 días", v.getVencidoTresMeses());
s.set("60 y 30 días", v.getVencidoDosMeses());
s.set("30 y 1 día", v.getVencidoMes());
s.set("1 a 30 días", v.getTreintaDias());
s.set("30 a 60 días", v.getSesentaDias());
s.set("60 a 90 días", v.getNoventaDias());
modelo.add(s);
modelo.setTitle("Title");
Related
Does any one have example code to add a direct tone to a PDF?
It is to a printer production to detect a rectangle to cut up.
this spot color is named « decoupe » and i need it for the rectangle.
I don’t need to modify the CMYK value of the separation.
I need to had a color named "decoupe" to the document and use this color to create a rectangle with this color, the printer detects this color to cut the document to the format. In the PDF document the line should be like that: 14 0 obj [/Separation /decoupe /DeviceCMYK << /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] /C1 [0.000000 0.000000 0.000000 0.000000] /FunctionType 2 /Domain [0 1] /N 1>>] endobj
This code adds a rectangle to an existing PDF with a spot color. I changed the c1 values to 1 1 1 1 so that something gets visible (yours was 0 0 0 0).
public static void main(String[] args) throws IOException
{
PDDocument doc = PDDocument.load(....);
COSArray array = new COSArray();
array.add(COSName.SEPARATION);
array.add(COSName.getPDFName("decoupe"));
array.add(COSName.DEVICECMYK); // alternate color
COSDictionary fdict = new COSDictionary();
fdict.setInt(COSName.FUNCTION_TYPE, 2);
COSArray range = new COSArray();
range.add(COSInteger.get(0));
range.add(COSInteger.get(1));
range.add(COSInteger.get(0));
range.add(COSInteger.get(1));
range.add(COSInteger.get(0));
range.add(COSInteger.get(1));
range.add(COSInteger.get(0));
range.add(COSInteger.get(1));
COSArray domain = new COSArray();
domain.add(COSInteger.get(0));
domain.add(COSInteger.get(1));
COSArray c0 = new COSArray();
c0.add(COSFloat.get("0"));
c0.add(COSFloat.get("0"));
c0.add(COSFloat.get("0"));
c0.add(COSFloat.get("0"));
COSArray c1 = new COSArray();
c1.add(COSFloat.get("1"));
c1.add(COSFloat.get("1"));
c1.add(COSFloat.get("1"));
c1.add(COSFloat.get("1"));
fdict.setItem(COSName.DOMAIN, domain);
fdict.setItem(COSName.RANGE, range);
fdict.setItem(COSName.C0, c0);
fdict.setItem(COSName.C1, c1);
fdict.setInt(COSName.N, 1);
PDFunctionType2 func = new PDFunctionType2(fdict);
array.add(func); // tint transform
PDColorSpace spotColorSpace = new PDSeparation(array);
PDPage page = doc.getPage(0);
PDPageContentStream cs = new PDPageContentStream(doc, page, AppendMode.APPEND, true, true);
PDColor color = new PDColor(new float[]{0.5f}, spotColorSpace);
cs.setStrokingColor(color);
cs.setLineWidth(10);
cs.addRect(50, 50, 300, 300);
cs.stroke();
cs.close();
doc.save(...);
}
What I used as help: the source code of PDSeparation.java, and the CreateGradientShadingPDF.java example from the source code download, that one has a type 2 function that I could easily copy and modify.
In fact, I've managed to do that BUT i get a problem that can be easily seen in the following image:
As you can see, there's a border between the image "jugar" and the final of the button. All I want to do is to remove that, so only the background image and the button "jugar" are seen. Here's my code:
public final class GUI extends Application {
#Override
public void start(final Stage primaryStage) throws InterruptedException, FileNotFoundException {
primaryStage.setTitle("CARCASSONE");
StackPane layout = new StackPane();
ImageView jugar = new ImageView(new Image(new FileInputStream("JUGAR.png")));
final Button openButton = new Button(null, jugar);
openButton.;
layout.getChildren().add(openButton);
BackgroundImage bI = new BackgroundImage(new Image(new FileInputStream("CARCASSONE.png")), null, null, null, null);
layout.setBackground(new Background(bI));
openButton.setOnAction(
new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent e) {
jugarPartida(primaryStage);
}
});
Scene inici = new Scene(layout, 610, 900);
primaryStage.setScene(inici);
primaryStage.show();
}
I must use JavaFX, so jbutton can't be used.
Any idea to solve that? Just want to remove that annoying border.
The problem with a transparent background is that there’s still an invisible rectangular area that responds to mouse clicks.
You can set the button’s region shape and its clip to a shape that matches your image bounds, so the Button effectively does not exist outside of those bounds:
openButton.setStyle("-fx-padding: 0;");
SVGPath shape = new SVGPath();
shape.setContent("M 18 0 "
+ "H 251 C 265 0 277 7 277 25 "
+ "V 52 C 277 69 265 76 251 76 "
+ "H 18 C 12 76 0 69 0 52 "
+ "V 25 C 0 7 12 0 18 0 "
+ "z");
shape.setFill(Color.BLACK);
openButton.setShape(shape);
openButton.setClip(shape);
Quick SVG path tutorial:
M means moveto (start drawing at that position)
H means draw horizontal line to the specified X position
V means draw vertical line to the specified Y position
C means curveto (draw Bézier curve using specified control points; last coordinate pair is the curve’s final endpoint)
z means close the shape
What you can do is apply css to set the color of openbutton to something like rgba(255, 255, 255, 0.00). You can also do this directly in code.
Something like String style = "-fx-background-color: rgba(255, 255, 255, 0.00);";
openButton.setStyle(style);
The last 0.0 is will make it transparent.
I need to implement a new "graphic generator". To ilustrate this requirement, I'll show an example of output using the old generator and the output of the one I'm trying to develop (or where I got so far).
My main issue right now is the space between the lines on the tick labels. The image must be 600x150, so I need to compress the text part of the graphic as much as I can (It doesn't need to be visually beautiful), but I could not find any suitable code so far.
Actually I need to eliminate as much "white spacing" as I can. If anyone have a hint how to implement the following, I would really appreciate:
Remove white gap between chart tittle and chart itself;
Remove white gap between tick labels and the bottow end of the image;
Remove the light gray line that represent the ticks on the bottom part of the chart. Right now the ticks labels and this line are overlapping.
This is the code I'm using to customize the chart:
CategoryPlot categoryplot = lineChart.getCategoryPlot();
lineChart.setTitle(
new org.jfree.chart.title.TextTitle(lineChart.getTitle().getText(),
new Font("SansSerif", Font.PLAIN, 10)
)
);
lineChart.setBackgroundPaint(Color.white);
categoryplot.setBackgroundPaint(Color.WHITE);
CategoryAxis domainAxis = new CategoryAxis();
domainAxis.setMaximumCategoryLabelLines(4);
categoryplot.setDomainAxis(domainAxis);
Font font = new Font("Courier", Font.PLAIN, 8);
categoryplot.getDomainAxis().setTickLabelFont(font);
categoryplot.getDomainAxis().setCategoryLabelPositionOffset(-6);
categoryplot.getDomainAxis().setTickLabelInsets(
new RectangleInsets(1.0, 1.0, 1.0, 1.0));
NumberAxis yAxis = (NumberAxis) categoryplot.getRangeAxis();
yAxis.setAutoRangeIncludesZero(false);
categoryplot.getRenderer().setSeriesStroke(
1,
new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {6.0f, 6.0f}, 0.0f
)
);
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setRangeGridlinesVisible(true);
categoryplot.setDomainGridlinePaint(Color.GRAY);
categoryplot.setRangeGridlinePaint(Color.GRAY);
categoryplot.getRenderer().setSeriesStroke(
2,
new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {6.0f, 6.0f}, 0.0f
)
);
categoryplot.getRenderer().setSeriesPaint(0, Color.BLUE);
categoryplot.getRenderer().setSeriesPaint(1, Color.RED);
categoryplot.getRenderer().setSeriesPaint(2, Color.RED);
LineAndShapeRenderer renderer = (LineAndShapeRenderer) categoryplot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
renderer.setSeriesShape(0, new Ellipse2D.Double(-5, -5, 10, 10));
I am Trying to have an HBox with two GridPanels, a bigger one in the left and a smaller one in the right (starting at the end of the right side the scene) however I cannot manage to get them in the positions I want to. This is how it looks right now. As you can see, the red GridPane is on top of the other one. The red panel should go all the wait to the right.
Moreover, I would like them to stay in the same position even if some buttons or text are added to either one of the GridPanes.
Here is my code:
//TEST BUTTONS PANEL
testButtonPane = new GridPane();
testButtonPane.setHgap(10);
testButtonPane.setVgap(9);
testButtonPane.setPadding(new Insets(140, 100, 0, 100));
questionLabel = new Label("Question:");
questionLabel.setPrefWidth(500.0);
questionLabel.setPrefHeight(50.0);
questionLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
testButtonPane.add(questionLabel,1,1);
testButtonPane.add(backButton,1,10);
backButton = new Button("BACK");
backButton.setOnAction(e -> primaryStage.setScene(sceneCreateTest));
backButton.setPrefWidth(140.0);
backButton.setPrefHeight(50.0);
backButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
testButtonPane.add(backButton,1,10);
//SCORE PANEL
scoreButtonPane = new GridPane();
scoreButtonPane.setHgap(10);
scoreButtonPane.setVgap(9);
scoreButtonPane.setPadding(new Insets(10, 10, 0, 10));
scoreButtonPane.setStyle("-fx-background-color: #AE3522;-fx-border-color: black");
statusTitleLabel = new Label("STATUS");
statusTitleLabel.setPrefWidth(160.0);
statusTitleLabel.setPrefHeight(50.0);
statusTitleLabel.setStyle("-fx-font: 30 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(statusTitleLabel,1,1,2,1);
scoreLabel = new Label("Score: ");
scoreLabel.setPrefWidth(130.0);
scoreLabel.setPrefHeight(50.0);
scoreLabel.setStyle("-fx-font: 20 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(scoreLabel,1,2);
timerLabel = new Label("Time: ");
timerLabel.setPrefWidth(130.0);
timerLabel.setPrefHeight(50.0);
timerLabel.setStyle("-fx-font: 20 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(timerLabel,1,3);
QInLabel = new Label("Question: ");
QInLabel.setPrefWidth(130.0);
QInLabel.setPrefHeight(50.0);
QInLabel.setStyle("-fx-font: 20 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(QInLabel,1,4);
//Makes possible to have two panes in the same scene/layout
HBox hBoxTest = new HBox();
hBoxTest.setSpacing(10.0);
hBoxTest.setPadding(new Insets(140,10,50,10));
hBoxTest.getChildren().addAll(testButtonPane, scoreButtonPane);
The test buttons panel should go in the left and the score panel is the red one and should go in the right. I hope you can help me. Thank you so much in advance. =)
I have created a custom widget--an SWT Group that consists of several buttons, labels, images and perhaps several other widgets I might need to add in the future. I would like to make this custom widget a tree item, so that I can get the indentation and the expand/collapse functionality of a tree.
Here is an image that shows what I am trying to achieve:
I created this example with the Google Web Toolkit and I'd like to implement it with SWT.
The SWT TreeItem has methods to set the text and the image, but I could not find a way to make the tree item be a custom widget. If it is not possible to associate custom widgets with SWT tree items, suggestions about other ways to organize custom widgets in a tree with indentation and expand/collapse functionality would be very helpful too. Thanks!
The PGroup widget from the Eclipse Nebula project does the job. It lets you enclose SWT Composites and supports collapsing and expanding. Indentation can be achieved by using layouts (e.g., GridLayout) for the contents of the PGroup and layout data (e.g., GridData) to specify the indentation of a component inside the PGroup.
The ExpandBar (which is a standard SWT widget) also seems like a possible solution, but I have not experimented with it.
It seems to be possible to use an event SWT.PaintItem to add custom drawing:
https://www.eclipse.org/articles/Article-CustomDrawingTableAndTreeItems/customDraw.htm
Source:
Embed custom widget in SWT Tree or Table
1 Display display = new Display();
2 Shell shell = new Shell(display);
3 shell.setBounds(10, 10, 350, 200);
4 Image xImage = new Image (display, 16, 16);
5 GC gc = new GC(xImage);
6 gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
7 gc.drawLine(1, 1, 14, 14);
8 gc.drawLine(1, 14, 14, 1);
9 gc.drawOval(2, 2, 11, 11);
10 gc.dispose();
11 final int IMAGE_MARGIN = 2;
12 final Tree tree = new Tree(shell, SWT.CHECK);
13 tree.setBounds(10, 10, 300, 150);
14 TreeItem item = new TreeItem(tree, SWT.NONE);
15 item.setText("root item");
16 for (int i = 0; i < 4; i++) {
17 TreeItem newItem = new TreeItem(item, SWT.NONE);
18 newItem.setText("descendent " + i);
19 if (i % 2 == 0) newItem.setData(xImage);
20 item.setExpanded(true);
21 item = newItem;
22 }
23 tree.addListener(SWT.MeasureItem, new Listener() {
24 public void handleEvent(Event event) {
25 TreeItem item = (TreeItem)event.item;
26 Image trailingImage = (Image)item.getData();
27 if (trailingImage != null) {
28 event.width += trailingImage.getBounds().width + IMAGE_MARGIN;
29 }
30 }
31 });
32 tree.addListener(SWT.PaintItem, new Listener() {
33 public void handleEvent(Event event) {
34 TreeItem item = (TreeItem)event.item;
35 Image trailingImage = (Image)item.getData();
36 if (trailingImage != null) {
37 int x = event.x + event.width + IMAGE_MARGIN;
38 int itemHeight = tree.getItemHeight();
39 int imageHeight = trailingImage.getBounds().height;
40 int y = event.y + (itemHeight - imageHeight) / 2;
41 event.gc.drawImage(trailingImage, x, y);
42 }
43 }
44 });
45 shell.open();
46 while (!shell.isDisposed()) {
47 if (!display.readAndDispatch()) display.sleep();
48 }
49 xImage.dispose();
50 display.dispose();