How to make JavaFX Chart NumberAxis only show Integer value,not double - charts

I'm trying to create a chart who's yAxis is designed to show number of employee number, so it must only show whole numbers.
But I found it's not that easy as I already tried to yAxis.setTickUnit(1) but it won't work when the values are small(etc. the max value is 3, it'll still show 0.5,1.5..., I only want tick value like 1,2,3,4..)
How Could I to achieve this?
According to #jewelsea 's answer, I tried this(In javafx 2.2 jdk7)
class IntegerStringConverter extends StringConverter<Number>{
public IntegerStringConverter() {
}
#Override
public String toString(Number object) {
if(object.intValue()!=object.doubleValue())
return "";
return ""+(object.intValue());
}
#Override
public Number fromString(String string) {
Number val = Double.parseDouble(string);
return val.intValue();
}
}
It's result is kind of acceptable. Double value's are gone, but there ticks are still there.

Set a tickLabelFormatter on the axis.

You can set the NumberAxis(double lowerBound, double upperBound, double tickUnit) values by using the constructor. This works fine for JaxaFX 8, in case people like me are still looking for this.
Source:
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/chart/NumberAxis.html

Related

Flutter - Add decimals on a dynamic value field

In Flutter i have a dropdown (we can call maxim field) to select total length. Then in index field we can add values with the same length of dropdown. When i add the value in index field i need to add '.000'.
I try to use masked package but i can't concatenate the index field value.
The code is similar to
int inputMaxValue=1;
var inputIndexValue = new MaskedTextController(mask: inputMaxValue.text+'.000');
Return
Only static members can be accessed in initializers
¿Anybody know can i fix this problem?
I think MaskedTextController is unnecessary in your case, simply change int inputMaxValue to double inputMaxValue and possibly add .toStringAsFixed(3) to achieve 3 decimals after the dot.
e.g.
double inputMaxValue = 1.0;
String inputIndexValue = "${inputMaxValue.toStringAsFixed(3)}";
However, if you want to keep the flutter_masked_text package - you should avoid using dynamic strings for the mask property. Error Only static members can be accessed in initializers appears supposedly because you declare the masked controller variable within the class, not in it's enclosing methods (e.g. initState).
In case of MaskedTextController, only static strings should be used for the mask property.
e.g. this is what I use to format phone number field:
MaskedTextController(mask: "(000) 000-0000")
maybe NumberFormat can help
import 'package:intl/intl.dart';
final price = 123;
final formater = NumberFormat("#,##0.000");
print(formater.format(price));
output: 123.00

get double value from bigdecimal without exponential java

is there a way to get double from BigDecimal without exponential?
Eg: I have an new BigDecimal("123456797676.897")
if i print new BigDecimal("123456797676.897").toString() it prints properly as 123456797676.897.
Now suppose if I try to print new BigDecimal("123456797676.897").doubleValue(), it prints with exponential like 1.23456797676897E11.
Is there any way I can get doublevalue with out exponential.
Thanks :)
The following program demonstrates that these are all exactly the same double:
new BigDecimal("123456797676.897").doubleValue()
123456797676.897
1.23456797676897E11
12.3456797676897E10
The Double toString method has to pick one representation for each value. For numbers greater than 107 it uses exponential notation with a single digit before the decimal point. That is a generally reasonable choice, but it is not always the right choice. If you want it displayed without the exponent use DecimalFormat. If you are just using the number, it makes no difference whether Double's toString would have displayed it with an exponent or not, and you don't need to do anything about it.
import java.math.BigDecimal;
public class Test {
public static void main(String[] args) {
double doubleValue = new BigDecimal("123456797676.897").doubleValue();
double simpleLiteral = 123456797676.897;
double exponent11Literal = 1.23456797676897E11;
double exponent10Literal = 12.3456797676897E10;
System.out.println(doubleValue == simpleLiteral);
System.out.println(doubleValue == exponent11Literal);
System.out.println(doubleValue == exponent10Literal);
}
}
output:
true
true
true

GWT-Charts ColumnFunction not working?

I just want to make sure I'm not doing something wrong before I file a bug/start digging in GWT-Charts code...
Trying to style a LineChart:
DataViewColumn ret = DataViewColumn.create(new ColumnFunction() {
#Override
public Object calc(DataTable dataTable, int row) {
if (dataTable.isValueNull(i, dataColumn)
|| dataTable.getValueNumber(i, dataColumn) < value) {
return "color: red";
}
return "color: green";
}
}, ColumnType.STRING);
ret.setRole(RoleType.STYLE);
(I had to add RoleType.STYLE myself, custom-built 0.9.11-SNAPSHOT off Master)
But adding that column results in (using new JSONObject(columns)):
{
"0":{"sourceColumn":0},
"1":{"sourceColumn":1, "label":"Data"},
"2":{"calc":{}, "type":"string", "role":"style"}
}
Note the empty set for "calc"?
I tried just doing a ColumnFunction for Data (returning a flat value) in case the "style" Role required more than just adding to the RoleType Enum, and that also doesn't seem to be getting passed through.
The JSNI in DataViewColumn.setCalc(ColumnFunction) seems to be right to me, so I'm not sure where the issue lies...
UPDATE:
Putting debugging statements in the ColumnFunction showed it to be running, but the output didn't seem to be getting used.
Turns out that DataViewColumn.setCalc was missing the return statement in its JSNI wrapper.
DataViewColumn.setCalc:
/**
* Sets a function that will be called for each row in the column to calculate a value for that cell.
*
* #param columnFunction a function for calculating each row value
*/
public final native void setCalc(ColumnFunction columnFunction) /*-{
this.calc = function(dataTable, row) {
columnFunction.#com.googlecode.gwt.charts.client.ColumnFunction::calc(Lcom/googlecode/gwt/charts/client/DataTable;I) (dataTable, row);
};
}-*/;
Was not returning the value calculated by the function, just calculating it.
Adding "return" to the line in the innermost block fixes the issue.

Change decimal seperator of GXT Numberfield to comma

Is it possible to change the decimal seperator of GXT Numberfield from point to comma? I searched and tried a lot, but can't find a solution.
When filling the form field of type "FloatField" with a number like 67,8 - the value of the field is switched to 67.8. So the field accecpts inputs with commas, but the NumberFormat to display it, is simply wrong.
How can i change that?
Thanks in advance, David.
ok, nobody had an answer, but a colleague of me have had the same problem and solved it. So, if anyone in future will search for it, here is the answer:
You can make your own FloatField class and override the behavior. The class (in the simpliest form) would be like this:
package org.example.myforms
public class FloatField extends NumberField<Float> {
/**
* Constructor
*/
public FloatField() {
super(new NumberPropertyEditor.FloatPropertyEditor());
init();
}
private void init () {
// disply float values with comma as decimal seperator
String pattern = "0.0;";
super.setFormat(NumberFormat.getFormat(pattern));
}
}
To use this field e.g. in your *.ui.xml you have to import your myform package:
<ui:UiBinder
...
xmlns:myform="urn:import:org.example.myforms"
>
Then you can use it:
<myform:FloatField ui:field="field_1" allowDecimals="true"/>

NTriplesParser extract textual value from string

I am using dotnetrdf and trying to parse some triples with NTriplesParser. I have my own handler RobHandler in which I process each triple in turn.
public class RobHandler : BaseRdfHandler
{
protected override bool HandleTripleInternal(Triple t)
{
string predicateUrl = ((BaseUriNode)(t.Predicate)).Uri.AbsoluteUri;
string value = t.Object.ToString();
}
}
This works fine but I want to get the object minus the language. My objects look like "Lincoln"#en. I could obviously write some code to remove the #en bit, but I'd rather use some library code rather than my own that hard-coded strings like #en. To do this I think I need to create a LiteralNode but there doesn't seem to be a way to get from a string which is what I have (my variable value) to a LiteralNode.
How can I extract just the textual value from an object string?
Actually I think I have the answer myself:
if (t.Object.NodeType == NodeType.Literal)
{
var node = (ILiteralNode)t.Object;
}