How to format numbers in Google API Linechart? - api

I need to format the numbers in the axis and the numbers that appear when you hover your mouse over the line chart.

There are two steps involved. The first step is to find out what pattern you should use; the second step is to put the pattern in the proper place in your code. To make this post more beautiful, I show you step 2 and then step 1.
Step 2: Putting the pattern in your code
Here's the code:
var options = {
hAxis: {format:'###,###'}
vAxis: {title: 'Time', format:'0.0E00'},
};
var formatter1 = new google.visualization.NumberFormat({pattern:'###,###'});
formatter1.format(dataTable, 0);
var formatter2 = new google.visualization.NumberFormat({pattern:'0.0E00'});
formatter2.format(dataTable, 1);
var fchartvar = new google.visualization.LineChart(document.getElementById('fchart'));
fchartvar.draw(dataTable, options);
vAxis: {title: 'Time', format:'0.0E00'} formats the labels on the vertical axis.
This formats the numbers you see when you hover over points on the line chart:
var formatter1 = new google.visualization.NumberFormat({pattern:'0.0E00'});
formatter1.format(dataTable, 1);
Note how (dataTable,0) formats the hAxis information while (dataTable,1) formats the vAxis information (again, which you see when you hover over the points on the line chart).
The last two lines of code:
var fchartvar = new google.visualization.LineChart(document.getElementById('fchart'));
fchartvar.draw(dataTable, options);
are for you two compare with your own chart. Replace fchartvar,dataTable and fchart by the names used in your code. If you're using something other than line chart, replace LineChart with the chart you're using.
An example of 0.0E00 is turning 1,234 into 1.2E03.
Step 1: Finding the right pattern
Google NumberFormat documentation
NumberFormat supports the following options, passed in to the constructor: (source: Google NumberFormat documentation)
decimalSymbol
A character to use as the decimal marker. The default is a dot (.).
fractionDigits
A number specifying how many digits to display after the decimal. The
default is 2. If you specify more digits than the number contains, it
will display zeros for the smaller values. Truncated values will be
rounded (5 rounded up).
groupingSymbol
A character to be used to group digits to the left of the decimal
into sets of three. Default is a comma (,).
negativeColor
The text color for negative values. No default value. Values can be
any acceptable HTML color value, such as "red" or "#FF0000".
negativeParens
A boolean, where true indicates that negative values should be
surrounded by parentheses. Default is true.
pattern
A format string. When provided, all other options are ignored, except
negativeColor.
The format string is a subset of the ICU pattern set. For instance,
{pattern:'#,###%'} will result in output values "1,000%", "750%", and
"50%" for values 10, 7.5, and 0.5.
prefix
A string prefix for the value, for example "$".
suffix
A string suffix for the value, for example "%".
ICU DecimalFormat Reference
As you might have noticed from the Google NumberFormat documentation above, you can find out more detailed information about formatting the numbers from the ICU DecimalFormat Reference. Here is some of the most important information from the ICU DecimalFormat Reference (it's in the 'middle' of the webpage):
A DecimalFormat pattern contains a postive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, a numeric part, and a suffix. If there is no explicit negative subpattern, the negative subpattern is the localized minus sign prefixed to the positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are ignored in the negative subpattern. That means that "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
The prefixes, suffixes, and various symbols used for infinity, digits, thousands separators, decimal separators, etc. may be set to arbitrary values, and they will appear properly during formatting. However, care must be taken that the symbols and strings do not conflict, or parsing will be unreliable. For example, either the positive and negative prefixes or the suffixes must be distinct for parse() to be able to distinguish positive from negative values. Another example is that the decimal separator and thousands separator should be distinct characters, or parsing will be impossible.
The grouping separator is a character that separates clusters of integer digits to make large numbers more legible. It commonly used for thousands, but in some locales it separates ten-thousands. The grouping size is the number of digits between the grouping separators, such as 3 for "100,000,000" or 4 for "1 0000 0000". There are actually two different grouping sizes: One used for the least significant integer digits, the primary grouping size, and one used for all others, the secondary grouping size. In most locales these are the same, but sometimes they are different. For example, if the primary grouping interval is 3, and the secondary is 2, then this corresponds to the pattern "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a pattern contains multiple grouping separators, the interval between the last one and the end of the integer defines the primary grouping size, and the interval between the last two defines the secondary grouping size. All others are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
Illegal patterns, such as "#.#.#" or "#.###,###", will cause DecimalFormat to set a failing UErrorCode.

If you need to simply format all numbers shown in the graph, in the hover and in the axis according to the locale of a country, the simplest in IMHO is to use the country code when loading the library.
E.g.:
google.charts.load('44', {packages: ['corechart', 'bar', 'sankey'], 'language': 'fr'});
That is the way I would format all numbers using space separators for thousands and a comma for the decimal place.

Related

The set of atomic irrational numbers used to express the character table and corresponding (unitary) representations

I want to calculate the irrational number, expressed by the following formula in gap:
3^(1/7). I've read through the related description here, but still can't figure out the trick. Will numbers like this appear in the computation of the character table and corresponding (unitary) representations?
P.S. Basically, I want to figure out the following question: For the computation of the character table and corresponding (unitary) representations, what is the minimum complete set of atomic irrational numbers used to express the results?
Regards,
HZ
You can't do that with GAP's standard cyclotomic numbers, as seventh roots of 3 are not cyclotomic. Indeed, suppose $r$ is such a root, i.e. a rot of the polynomial $f = x^7-3 \in \mathbb{Q}[x]$. Then $r$ is cyclotomic if and only if the field extension \mathbb{Q}[x] is a subfield of a cyclotomic field. By Kronecker-Weber this is equivalent to that field being an abelian extension, i.e., the Galois group is abelian. One can check that this is not the case here (the Galois group is a semidirect product of C_7 with C_6).
So, $r$ is not cyclotomic.

Constants (constant variables) in ALFA

The OASIS Working Draft 01 for ALFA (alfa-for-xacml-v1.0-wd01) of 10 March 2015 says about constant values
3.15 Constant Values
Constant values can appear in the policy expressions. ALFA supports constants of type strings, integers,
doubles and Booleans directly. Strings are quoted with single or
double quotes. Integers consist of a number and optionally a minus
sign. Double consists of a number with a decimal dot and optionally a
minus sign. Booleans consist of the value true and false, without
quotes. Other datatypes are represented using a string followed by a
colon and the name of the datatype..
What that means is, you can use constant values like in that example (while report is the constant value):
target clause requestedType == "report"
But the thing is, once the ALFA files grow and you have written the constant value report all over, you might want to change the constant value into let's say my.company.attributes.medicalReport. In order to do that you have to find and replace all occurrences of the constant value.
Therefore (for the sake of avoiding redundancy) constants have been invented in other languages, where you define smth. like
const string REPORT_TYPE = "my.company.attributes.medicalReport"
or even more performant:
const integer REPORT_TYPE_ID = 3
or even more elegant:
const enum SUBJECT_TYPES { PATIENT, USER, EXAM, REPORT }
With those constants being defined I could write my target like:
target clause requestedType == REPORT_TYPE_ID
Does ALFA support constants or is there a way to "emulate" them (maybe a function that returns the desired value)?
Not yet! It is definitely a feature we want to have. We've had similar requests so stay tuned.

How to treat numbers inside text strings when vectorizing words?

If I have a text string to be vectorized, how should I handle numbers inside it? Or if I feed a Neural Network with numbers and words, how can I keep the numbers as numbers?
I am planning on making a dictionary of all my words (as suggested here). In this case all strings will become arrays of numbers. How should I handle characters that are numbers? how to output a vector that does not mix the word index with the number character?
Does converting numbers to strings weakens the information i feed the network?
Expanding your discussion with #user1735003 - Lets consider both ways of representing numbers:
Treating it as string and considering it as another word and assign an ID to it when forming a dictionary. Or
Converting the numbers to actual words : '1' becomes 'one', '2' as 'two' and so on.
Does the second one change the context in anyway?. To verify it we can find similarity of two representations using word2vec. The scores will be high if they have similar context.
For example,
1 and one have a similarity score of 0.17, 2 and two have a similarity score of 0.23. They seem to suggest that the context of how they are used is totally different.
By treating the numbers as another word, you are not changing the
context but by doing any other transformation on those numbers, you
can't guarantee its for better. So, its better to leave it untouched and treat it as another word.
Note: Both word-2-vec and glove were trained by treating the numbers as strings (case 1).
The link you provide suggests that everything resulting from a .split(' ') is indexed -- words, but also numbers, possibly smileys, aso. (I would still take care of punctuation marks). Unless you have more prior knowledge about your data or your problem you could start with that.
EDIT
Example literally using your string and their code:
corpus = {'my car number 3'}
dictionary = {}
i = 1
for tweet in corpus:
for word in tweet.split(" "):
if word not in dictionary: dictionary[word] = i
i += 1
print(dictionary)
# {'my': 1, '3': 4, 'car': 2, 'number': 3}
The following paper can be helpful: http://people.csail.mit.edu/mcollins/6864/slides/bikel.pdf
Specifically, page 7.
Before they use an <unknown> tag they try to replace alphanumeric symbol combination with common pattern names tags, such as:
FourDigits (good for years)
I've tried to implement it and it gave great results.

Is format ####0.000000 different to 0.000000?

I am working on some legacy code at the moment and have come across the following:
FooString = String.Format("{0:####0.000000}", FooDouble)
My question is, is the format string here, ####0.000000 any different from simply 0.000000?
I'm trying to generalize the return type of the function that sets FooDouble and so checking to make sure I don't break existing functionality hence trying to work out what the # add to it here.
I've run a couple tests in a toy program and couldn't see how the result was any different but maybe there's something I'm missing?
From MSDN
The "#" custom format specifier serves as a digit-placeholder symbol.
If the value that is being formatted has a digit in the position where
the "#" symbol appears in the format string, that digit is copied to
the result string. Otherwise, nothing is stored in that position in
the result string.
Note that this specifier never displays a zero that
is not a significant digit, even if zero is the only digit in the
string. It will display zero only if it is a significant digit in the
number that is being displayed.
Because you use one 0 before decimal separator 0.0 - both formats should return same result.

Filtering rows in Pentaho

I have a dataset with columns containing numbers. However, some of the rows in that column have missing data. Instead of numbers, a dash (-) is placed in the cell.
What I want to happen is to separate those rows with a dash and output them to a separate excel file. Those without the dash, should output to a csv file.
I tried the "filter rows" but it gives me an error:
Unexpected conversion error while converting value [constant String] to a Number
constant String : couldn't convert String to number
constant String : couldn't convert String to number : non-numeric character found at position 1 for value [-]
My condition is if
Column1 CONTAINS - (String)
You cant try to convert to number in the select step,and handler the error, if can not convert to number that mean that is (-)
You can convert missing value indicators (like a dash or any other string) to null in Text-File-Input - see field option "Null if". That way you still can use the metadata detection feature and will not trip over a dash arriving in a Number field.
With CSV-File-Input you should stick to the String datatype until a Null-If step has cleansed the values, so you can change the datatype to Number in a Select-Values step.
If you must preserve the dash character, don't use metadata detection (as it suggests datatype Number) or use more rows to sample (so a field with a dash is encountered) or just revert the datatype to String again before saving and running the transformation.
My solution lies on the first 'Replace in String'. I replaced the dash into something numeric and can easily be distinguished from the rest of the numbers (I used 9999) and carried on with the rest of my process.
In filter rows, I had no problems anymore with the data type because both my variables and condition contained numbers, therefore, it no longer had to convert anything.
After filter rows, I added the 'Null-if' to remove the random 9999 that I used
just to have something to replace the dash.
After that, the separation was made just as I hope it would.
Thanks to #marabu for the Null-if idea.