JavaFX 2.2 How to setLowerBound and setUpperBound in DateAxis in LineChart generated by FXML - date

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"

Related

Issue removing and readding series to chart

I'm trying to write a method in GWT to override the series.show function for all Highcharts series, on show I want to essentially copy the series, remove the series from the chart, and readd it so that showing the series will redraw the line (instead of the default behavior where the line appears and the chart redraws). I have this modeled in a Jsfiddle: http://jsfiddle.net/ax3o8uf3/16/
I used Moxie's highcharts wrapper for GWT and used the setSeriesPlotOptions() method to set the series show event handler and call this native method from inside the onShow().
public static native void showSeries(JavaScriptObject series, JavaScriptObject chart) /*-{
var options = series.options;
options.color = series.color;
options.index = series.index;
options.marker.symbol = series.symbol;
series.remove();
options.visible = true;
chart.addSeries(options);
}-*/;
and everything worked fine. Then we updated the project's highcharts and highstock.js files and it broke everything. Now hiding and showing a series in the legend will cause it to redraw fine for the first series you do it for, but as soon as you try and show another series it breaks and goes back to the default functionality for all series. Any ideas on what I'm doing wrong or what might be causing it to not work after showing a second series on the graph?
I'm not sure why but for some reason using the seriesShowEventHandler() caused it to break after trying to show more than one series, the solution I came up with was something like this:
setSeriesPlotOptions(new SeriesPlotOptions().setSeriesLegendItemClickEventHandler(new SeriesLegendItemClickEventHandler() {
#Override
public boolean onClick(SeriesLegendItemClickEvent seriesLegendItemClickEvent) {
Series series = getSeries(seriesLegendItemClickEvent.getSeriesId());
if(seriesLegendItemClickEvent.isVisible()) {
series.hide();
} else if((series.getOptions().get("type").toString()).equals("\"line\"")){
removeAndReAddSeries(getNativeChart(), series.getNativeSeries());
} else {
series.show();
}
return false;
}
}));

How can I use a zk-chart on click?

I have a great problem with ZK charts!
I have 2 type of chart: a chart with data of the current day (so this chart is generated automatically) and a chart with data of a clicked date.
The first chart works correctely, the second not!
If I have clicked on a date, I build a graph! But it's impossible to modify the label position or name of label! And I need to modify these things. This is my graph:
<charts width="1700" style="height: 400px" type="line" model="#bind(vm.chart2)" title="">
</charts>
When I clicked I call this method:
#Command
#NotifyChange("chart2")
public ChartsModel viewGraph(#BindingParam("self") Group self){
String a = self.getLabel();//this is for passed a parameter
ServiceImpl usr = new ServiceImpl();
chart2 = usr.viewGraph(a);
return chart2;
}
viewGraph is so built:
#Override
public ChartsModel viewGraph(String data) {
//chart2 = new Charts();
chart2.setModel(LineLabelsData.setCategoryModel2(data));
chart2.getXAxis().getLabels().setRotation(180);
chart2.getYAxis().getTitle().setText("TEXT");
chart2.getTooltip().setEnabled(false);
chart2.getXAxis().getLabels().setRotation(180);
LinePlotOptions linePlotOptions =
chart2.getPlotData().getPlotOptions().getLine();
linePlotOptions.setEnableMouseTracking(false);
linePlotOptions.getDataLabels().setEnabled(true);
return chart2.getModel();
}
If I print something in this method my console view it correctely! The problem is that
chart2.getYAxis().getTitle().setText("TEXT");
does not work like
chart2.getXAxis().getLabels().setRotation(180);
How can I change that values?
To change yAxis title, you can simply call chart2.getYAxis().setTitle("title");
You may want to post your questions in ZK Forum rather than stackoverflow as our community users are experienced in ZK, and can help you quicker.

HighCharts Stock Chart error code 18

I am trying to add series to my chart application using gwt-highchart (using the latest gwt-highchart 1.6.0 and Highstock 2.3.4 versions). Everything seems fine until the third series. When I try to add the third one I got this error:
com.google.gwt.core.client.JavaScriptException: (String)
#org.moxieapps.gwt.highcharts.client.BaseChart::nativeAddSeries(Lcom/google/gwt/core
/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;ZZ)([JavaScript
object(4953), JavaScript object(5135), bool: true, bool: true]): Highcharts error #18:
www.highcharts.com/errors/18
And here is my code (runs within a loop):
// Create a new serie with a new yAxis
Series newSeries = chart.createSeries().setYAxis(index).setPlotOptions(new LinePlotOptions().setColor(tag.getColor()));
// Set new yAxis options
chart.getYAxis(index).setPlotLines(chart.getYAxis(index).createPlotLine().setValue(0).setWidth(1).setColor(tag.getColor())).setLabels(new YAxisLabels().setEnabled(false)).setTickLength(0).setOffset(60).setStartOnTick(false)
.setEndOnTick(false).setGridLineWidth(0).setMaxPadding(DEFAULT_YAXIS_MAX_PADDING).setMinPadding(DEFAULT_YAXIS_MIN_PADDING)
.setAxisTitle(new AxisTitle().setText(null).setStyle(new Style().setColor(tag.getColor())));
// Add the serie to the chart
chart.addSeries(newSeries.setName("Test " + index));
First two series are OK as I said before but third one throws the above exception (when I debug the application, I can see the newly created yAxis references).
Here is the line which throws the exception:
chart.addSeries(newSeries.setName("Test " + index));
Thanks
I've figured it out finally!
GWT-HighCharts seems to be the problem. It does not add the new YAxis to the Chart at all. So you must add YAxis via native calls like this;
private static native void nativeAddAxis(JavaScriptObject chart, JavaScriptObject axisOptions, boolean isX, boolean redraw, boolean animationFlag) /*-{
chart.addAxis(axisOptions, isX, redraw, animationFlag);
}-*/;
Just call this native method before adding the new series.
// Create new series
Series newSeries = chart.createSeries().setYAxis(index);
newSeries.setPlotOptions(new LinePlotOptions().setColor(tag.getColor()));
newSeries.setName(index + 1 + ") ");
// Create a new YAxis
YAxis yAxis = chart.getYAxis(index).setPlotLines(chart.getYAxis(index).createPlotLine().setValue(0).setWidth(1).setColor(tag.getColor())).setLabels(new YAxisLabels().setEnabled(false)).setTickLength(0).setOffset(60)
.setStartOnTick(false).setEndOnTick(false).setGridLineWidth(0).setPlotLines().setMaxPadding(DEFAULT_YAXIS_MAX_PADDING).setMinPadding(DEFAULT_YAXIS_MIN_PADDING)
.setAxisTitle(new AxisTitle().setText(null).setStyle(new Style().setColor(tag.getColor())));
// IMPORTANT!: New YAxis must be added to the chart via native calls since gwt-highcharts wrapper doesn't do that properly!
nativeAddAxis(chart.getNativeChart(), yAxis.getOptions().getJavaScriptObject(), false, false, false);
// Physical attach
chart.addSeries(newSeries);
Here is the cause of this type of errors:
If you are using GWT-HighCharts wrapper, you must make the configuration before adding chart to DOM! It seems that after adding it to the DOM, any configuration changes does not seem to work at all!
Happy coding!
please check the index value.
if index is more than the axis count this error may occur
highcharts error #18 indicates that the axis trying to access does not exist.
here is the link http://www.highcharts.com/errors/18
Hope that will help you

centering the contents of an column in GWT Bootstrap cell table

I have an cell table and the column data are the check boxes i want align these check boxes to center of that column
i tried withcolumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
and using text-align:middle in css. but it doesn't seem to work .Please help
Column<Person, Boolean> checkColumn = new Column<Person, Boolean>(
new CheckboxCell(true, false)) {
#Override
public Boolean getValue(Person object) {
// check box function
}
};
checkColumn.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
Works fine for me.
Since you didn't provide much code I can only make several assumptions:
Check that your cell table CSS [if your using custom ones] isn't over writing the alignment
Double check your aligning the right column [happens]
If you are using UiBinder, check to make sure you only set alignment in either your java class or the xml

Legend hides chart created using JFreeChart

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.