View piaChart decimal values - primefaces

I have the following values that I would like to present via piaChart
3.0283506
0.25773194
95.87629
0.83762884
How can I configure the dataLabelFormatString so it will show also values that are less than 1 so the result will look like this:
3.02
0.25
95.8
0.83
Thanks

If i understand correctly you want to show the first 4 chars of your values?
In that case you want to use %4.4s in your dataLabelFormatString.
double num1 = 3.0283506;
double num2 = 0.25773194;
double num3 = 95.87629;
double num4 = 0.83762884;
System.out.format("%4.4s%n", num1);
System.out.format("%4.4s%n", num2);
System.out.format("%4.4s%n", num3);
System.out.format("%4.4s%n", num4);
produces:
3.02
0.25
95.8
0.83

It is possible to place the decimal format datalabel by using the setting.
rendererOptions: {
fill: true,
showDataLabels: true,
dataLabelFormatString: '%.2f%'
}

Related

How does the 'k' modifier in FINDC() work in SAS?

I'm reading through the book, "SAS Functions by Example - Second Edition" and having trouble trying to understand a certain function due to the example and output they get.
Function: FINDC
Purpose: To locate a character that appears or does not appear within a string. With optional arguments, you can define the starting point for the search, set the direction of the search, ignore case or trailing blanks, or look for characters except the ones listed.
Syntax: FINDC(character-value, find-characters <,'modifiers'> <,start>)
Two of the modifiers are i and k:
i ignore case
k count only characters that are not in the list of find-characters
So now one of the examples has this:
Note: STRING1 = "Apples and Books"
FINDC(STRING1,"aple",'ki')
For the Output, they said it returns 1 because the position of "A" in Apple. However this is what confuses me, because I thought the k modifier says to find characters that are not in the find-characters list. So why is it searching for a when the letter "A", case-ignored, is in the find-characters list. To me, I feel like this example should output 6 for the "s" in Apples.
Is anyone able to help explain the k modifier to me any better, and why the output for this answer is 1 instead of 6?
Edit 1
Reading the SAS documentation online, I found this example which seems to contradict the book I'm reading:
Example 3: Searching for Characters and Using the K Modifier
This example searches a character string and returns the characters that do
not appear in the character list.
data _null_;
string = 'Hi, ho!';
charlist = 'hi';
j = 0;
do until (j = 0);
j = findc(string, charlist, "k", j+1);
if j = 0 then put +3 "That's all";
else do;
c = substr(string, j, 1);
put +3 j= c=;
end;
end;
run;
SAS writes the following output to the log:
j=1 c=H
j=3 c=,
j=4 c=
j=6 c=o
j=7 c=!
That's all
So, is the book wrong?
The book is wrong.
511 data _null_;
512 STRING1 = "Apples and Books" ;
513 x=FINDC(STRING1,"aple",'ki');
514 put x=;
515 if x then do;
516 ch=char(string1,x);
517 put ch=;
518 end;
519 run;
x=6
ch=s

Calling .csv file into Octave

I have a code written in C++ that outputs a .csv file with data in three columns (Time, Force, Height). I want to plot the data using Octave, or else use the octave function plot in the C++ file (I'm aware this is possible but I don't necessarily need to do it this way).
Right now I have the simple .m file:
filename = linear_wave_loading.csv;
M = csvread(filename);
Just to practice bringing this file into octave (will try and plot after)
I am getting this error.
error: dlmread: error parsing range
What is the correct method to load .csv files into octave?
Edit: Here is the first few lines of my .csv file
Wavelength= 88.7927 m
Time Height Force(KN/m)
0 -20 70668.2
0 -19 65875
0 -18 61411.9
0 -17 57256.4
Thanks in advance for your help.
Using octave 3.8.2
>> format long g
>> dlmread ('test.csv',' ',2,0)
ans =
0 0 0 -20 70668.2
0 0 0 -19 65875
0 0 0 -18 61411.9
0 0 0 -17 57256.4
General, use dlmread if your value separator is not a comma. Furthermore, you have to skip the two headlines.
Theoretical dlmread works with tab separated values too '\t', but this failes with you given example, because of the discontinuous tab size (maybe it's just a copy paste problem), so taking one space ' ' as separator is a workaround.
you should better save your .csv file comma separated
Wavelength= 88.7927 m
Time Height Force(KN/m)
0, -20, 70668.2
0, -19, 65875
0, -18, 61411.9
0, -17, 57256.4
Then you can easily do dlmread('file.csv',',',2,0).
You can try my csv2cell(not to be confused with csv2cell from io package!) function (never tried it < 3.8.0).
>> str2double(reshape(csv2cell('test.csv', ' +',2),3,4))'
ans =
0 -20 70668.2
0 -19 65875
0 -18 61411.9
0 -17 57256.4
Usually it reshaped successful automatically, but in case of space seperators, it often failed, so you have to reshape it by your self (and convert to double in any case).
And when you need your headline
>> reshape(csv2cell('test.csv', ' +',1),3,5)'
ans =
{
[1,1] = Time
[2,1] = +0
[3,1] = +0
[4,1] = +0
[5,1] = +0
[1,2] = Height
[2,2] = -20
[3,2] = -19
[4,2] = -18
[5,2] = -17
[1,3] = Force(KN/m)
[2,3] = 70668.2
[3,3] = 65875
[4,3] = 61411.9
[5,3] = 57256.4
}
But take care, then everything is a string in your cell.
Your not storing you .csv filename as a string.
Try:
filename = 'linear_wave_loading.csv';

MS Access to Tsql: What is Asc(UCase(String)) - 64?

Does anyone have any idea what this Asc function is doing (-64)? Thanks again in advance.
Access - IIF(Trim(NZ(MCATw)) = "", 0, Abs(Asc(UCase(MCATw)) -64)) as MCATwNo
I don't understand what the -64 is doing?
It's probably converting the first letter of a string to a numeric value 1-26. The upper case letters A - Z have ASCII values of 65 - 90, so ASC("A") becomes 65, and 65 - 64 is 1. Thus A - Z becomes 1 - 26. Assuming that MCATw is a string, ASC will only apply to the first character.

Understanding Encoding Type

i have an application which converts each character in my string to 3digit number, it seems to be something like ASCII but its not that, im trying to figure it out but i cant understand:
somefunction(){
a => 934 // a will be converted to 934
b => 933 // b will be converted to 933
1 => 950 // 1 will be converted to 950
0 => 951 // 0 will be converted to 951
}
i know ASCII but i don't understand this, please help if know what type of encoding type this is.
Thanks You :)
Here's one possibility (ord returns the ASCII value of the character), but I think you'd really need several more data points to know for certain.
>>> for c in 'ab10': print c, 999 - ord(c.upper())
...
a 934
b 933
1 950
0 951

What's the correct way to expand a [0,1] interval to [a,b]?

Many random-number generators return floating numbers between 0 and 1.
What's the best and correct way to get integers between a and b?
Divide the interval [0,1] in B-A+1 bins
Example A=2, B=5
[----+----+----+----]
0 1/4 1/2 3/4 1
Maps to 2 3 4 5
The problem with the formula
Int (Rnd() * (B-A+1)) + A
is that your Rnd() generation interval is closed on both sides, thus the 0 and the 1 are both possible outputs and the formula gives 6 when the Rnd() is exactly 1.
In a real random distribution (not pseudo), the 1 has probability zero. I think it is safe enough to program something like:
r=Rnd()
if r equal 1
MyInt = B
else
MyInt = Int(r * (B-A+1)) + A
endif
Edit
Just a quick test in Mathematica:
Define our function:
f[a_, b_] := If[(r = RandomReal[]) == 1, b, IntegerPart[r (b - a + 1)] + a]
Build a table with 3 10^5 numbers in [1,100]:
table = SortBy[Tally[Table[f[1, 100], {300000}]], First]
Check minimum and maximum:
In[137]:= {Max[First /# table], Min[First /# table]}
Out[137]= {100, 1}
Lets see the distribution:
BarChart[Last /# SortBy[Tally[Table[f[1, 100], {300000}]], First],
ChartStyle -> "DarkRainbow"]
X = (Rand() * (B - A)) + A
Another way to look at it, where r is your random number in the range 0 to 1:
(1-r)a + rb
As for your additional requirement of the result being an integer, maybe (apart from using built in casting) the modulus operator can help you out. Check out this question and the answer:
Expand a random range from 1–5 to 1–7
Well, why not just look at how Python does it itself? Read random.py in your installation's lib directory.
After gutting it to only support the behavior of random.randint() (which is what you want) and removing all error checks for non-integer or out-of-bounds arguments, you get:
import random
def randint(start, stop):
width = stop+1 - start
return start + int(random.random()*width)
Testing:
>>> l = []
>>> for i in range(2000000):
... l.append(randint(3,6))
...
>>> l.count(3)
499593
>>> l.count(4)
499359
>>> l.count(5)
501432
>>> l.count(6)
499616
>>>
Assuming r_a_b is the desired random number between a and b and r_0_1 is a random number between 0 and 1 the following should work just fine:
r_a_b = (r_0_1 * (b-a)) + a