i've to create a chart using library JFreeChart, i try this:
TimeSeriesCollection dataset = new TimeSeriesCollection();
ArrayList<MyObject> list = this.FillArray();
MyObject tmp;
String date[];
for(int i=0;i<list.size();i++){
tmp = list.get(i);
ArrayList<MyObject1> obj = this.FillArray1(tmp);
TimeSeries pop = new TimeSeries(tmp.getName(),Day.class);
for(MyObject1 ob1 : obj){
date = ob1.getDate().split("-");
Day day = new Day(Integer.parseInt(date[0]), Integer.parseInt(date[1]), Integer.parseInt(date[2]));
pop.addOrUpdate(day, ob1.getValue());
}
dataset.addSeries(pop);
}
My problem borns when the number of object is very high and legend will cover the panelchart. What can i do? is possible to add a scrollpane to the legend?
Legends are rendered in a LegendTitle, the first Title added to List subtitles when the JFreeChart instance is constructed with the createLegend parameter set to true. Because JFreeChart is not a Container, nor is Title a Component, adding a LegendTitle to a JScrollPane is not supported.
You can always invoke getLegendItems() and render the items in a Scrollable Container such as JList or JTable. To avoid duplication, set createLegend to false.
Related
I put 8 charts in my form . I want to set some parameters of the charts in a loop , not one by one . Charts don't belong to Controls . Any ideas ?
You can add all your Chart objects to a Collection i.e. to a List<Chart> and iterate over them to modify all their properties like this:
do this in your form constructor
List<Chart> _charts = new List<Chart>();
_charts.Add(chart1);
_charts.Add(chart2);
Call this method when you want to change all background colors to black.
void changeChartsBackground()
{
foreach(var chart in _charts)
{
chart.Background = Color.Black;
}
}
Finally it looks like this:
List<Control> _charts = new List<Control>();
_charts.Add(chart1);
_charts.Add(chart2);
foreach (Control _chart in _charts)
{
_chart.BackColor = Color.Blue;
}
I use iTextSharp v5.5.6
I'm creating a large table.
To be consistent in my layout I want to use the DefaultCell class to set some default settings like font, padding and alignment.
I'm not doing something correct because the settings are not applied to my cells.
Here's some code:
var table = new PdfPTable(2)
{ KeepTogether = true, TotalWidth = printWidth, LockedWidth = true,
HorizontalAlignment = 0, SpacingBefore = 0, SpacingAfter = 15f };
// Set default values:
table.DefaultCell.Colspan = 1;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.DefaultCell.Padding = 5f;
table.DefaultCell.PaddingLeft = 5f;
table.DefaultCell.PaddingBottom = 5f;
table.DefaultCell.VerticalAlignment = Element.ALIGN_BOTTOM;
table.DefaultCell.BorderWidthBottom = 0f;
table.DefaultCell.Phrase = new Phrase { Font = Blue11BoldFont };
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.AddCell(new PdfPCell(new Phrase("Foo"))
{ HorizontalAlignment = Element.ALIGN_CENTER, MinimumHeight = 20f });
table.AddCell(new PdfPCell(new Phrase("Bar", Black10BoldFont))
{ Colspan = 4, HorizontalAlignment = Element.ALIGN_CENTER });
I would have expected my first cell would use my blue font and padding is applied.
But nothing is applied. In fact when I remove the DefaultCell lines I get the same result.
I've been searching for hours now and most samples I've found use something similar.
Any suggestion is much appreaciated.
You are creating PdfPCell objects yourself. In that case, the default cell is always ignored.
See What is the PdfPTable.DefaultCell property used for?
When creating a PdfPTable, you add cells.
One way is to create a PdfPCell object and to add that cell with the addCell() method. In this case, you are responsible to define the properties of each individual cell.
Another way is to use a short-cut: you don't create a PdfPCell, but you add a String or a Phrase to the table with the addCell() method. In this case, a PdfPCell is created internally using default properties. You can change the default properties by changing the properties of the default cell. The default cell is obtained using the getDefaultCell() method.
This is not a bug, this is by design. You are misinterpreting the meaning of the concept of the "default cell". Note that this concept was explained in the free ebook The Best iText Questions on StackOverflow.
If you want to be consistent in your layout, the best way to do this, is by creating your own createCell() method that creates a PdfPCell to which you apply all the properties for which you were using the default cell.
I have whit JavaFX Scene builder made layout for my application. On my linechart I drow some graphs depending on dates. By default JavaFX LineChart doesn't support dates. So I use this librariy http://myjavafx.blogspot.com/2013/09/javafx-charts-display-date-values-on.html and it works fine.
Librray also allows setLowerBound and setUpperBound methods. I havev wrote code bit it doesn't work.
My FXML code (ONLY FOR LINECHART):
<LineChart fx:id="lineChart" animated="false">
<xAxis>
<DateAxis side="BOTTOM" label="Napoved kalibracije" fx:id="dateAxis"/>
</xAxis>
<yAxis >
<NumberAxis label="Odstopanja v %" lowerBound="0" upperBound="95" tickUnit="10"/>
</yAxis>
</LineChart>
As you can see I have set id="dateAxis" so I can refer from main class to layout crate as I mentioned by Scene Builder.
Code in main class(ONLY FOR DATAAXIS) wher I get ID form FXML:
Scene scena = primaryStage.getScene();
DateAxis dA = (DateAxis) scena.lookup("#dateAxis");
dA.setUpperBound(new GregorianCalendar(2016,8,23).getTime());
primaryStage.show();
System.out.println(dA);
returns:
DateAxis[id=dateAxis, styleClass=axis]
what means that is working fine. But my chart on xAxis(DateAxis) doesn't go to 23th of August 2016.
I would be very grateful if we solve this problem.
There are two changes you need to apply, The first is to add the constructor of the date axis, two arguments: lower bound + upper bound,
example:
final DateAxis xAxis = new DateAxis(new Date(2013-1900,1,4),new Date(2013-1900,30,14));
The other change is to change the source code of class DateAxis , look for this part of the code (just search for "true" to find the specific line )
public DateAxis(Date lowerBound, Date upperBound) {
this();
setAutoRanging(true); // change it to "false"
setLowerBound(lowerBound);
setUpperBound(upperBound);
}
and change the "setAutoRanging" argument to "false"
There is a List in a LWUIT application. I want to make odd rows and even rows to be of different colors. How to achieve that ?
You can set two differents UIIDs to the rows. Setting this UIID you can modify selectively the colors of your rows.
EDIT
Ok this will be more difficult.
You need to make a Render and set it in your List with List.setRender(Render r).
The ´Render´ class will extend from ListCellRender. In this class you can set UIID to the Render, setting its Selected or Unselected styles.
See this example. #Shai Almog could have more info for your problem.
http://www.lwuit.com/2008/07/lwuit-list-renderer-by-chen-fishbein.html
What you need is the Generic List Cell Renderer, you will probably have to create the styles in code, or set the UIID from the resource editor.
List list = new List(createGenericListCellRendererModelData());
list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
private Container createGenericRendererContainer() {
Container c = new Container(new BorderLayout());
c.setUIID("ListRenderer");
Label name = new Label();
name.setFocusable(true);
name.setName("Name");
c.addComponent(BorderLayout.CENTER, name);
Label surname = new Label();
surname.setFocusable(true);
surname.setName("Surname");
c.addComponent(BorderLayout.SOUTH, surname);
CheckBox selected = new CheckBox();
selected.setName("Selected");
selected.setFocusable(true);
c.addComponent(BorderLayout.WEST, selected);
return c;
}
private Hashtable[] createGenericListCellRendererModelData() {
Hashtable[] data = new Hashtable[5];
data[0] = new Hashtable();
data[0].put("Name", "Shai");
data[0].put("Surname", "Almog");
data[0].put("Selected", Boolean.TRUE);
data[1] = new Hashtable();
data[1].put("Name", "Chen");
data[1].put("Surname", "Fishbein");
data[1].put("Selected", Boolean.TRUE);
data[2] = new Hashtable();
data[2].put("Name", "Ofir");
data[2].put("Surname", "Leitner");
data[3] = new Hashtable();
data[3].put("Name", "Yaniv");
data[3].put("Surname", "Vakarat");
data[4] = new Hashtable();
data[4].put("Name", "Meirav");
data[4].put("Surname", "Nachmanovitch");
return data;
}
Full details here : http://lwuit.blogspot.com/2011/03/list-rendering-easy-way-generic-list.html (code gotten from this link).
I have a label which i need to create as per the size of my record
like if there are 2 records from database , my method should check and create 2 new labels at runtime , if 10 records there should be 10 labels to be created at run time
I am able to create 10 new labels at run time but how can i name them differently
some thing like
for (int i =0;i<array.size();i++)
{
Label lbl = new Label();
}
in this way there are 10 labels and showing perfectly , but all ten have the same name i.e lbl can this name could also be change like lbl1,lbl2,lbl3...
is it possible in GWT
Thanks
The thing you want to do isn't poosible in any programming language.
The solution you are searching for is storing them inside a list and then access the labels via the index. Eg. if you want the first label you say List[0]
GWT supports such list, the easiast for you to use ist the ArrayList!
here is some more or less pseudo code:
ArrayList<Label> labelList = new ArrayList<Label>();
for (int i =0;i<array.size();i++)
{
Label lbl = new Label();
labelList.add(lbl);
}
...
//the first item has the index 0!
Label lbl1 = labelList.get(0);
..
//doing stuff with the first label
...
//getting the secont label
Label lbl2 = labelList.get(1);
...
//you get the idea right
...