Blank chart display when load Highchart data using ajax - java

I'm having problem with highchart.
I'm trying to populate data from struts action by using ajax.
Here is my code
Jquery
$.getJSON("<%=request.getContextPath()%>/c/MonthlyGraphAjax?method=monthlyGraph&selectionList=${selectionList}&reportDateMonth=${reportDateMonth}", function(data){
/*manual insert*/
dchart.xAxis.categories.push(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30)
dchart.series.push({name:'John',data:[99,155,148,136,121,0,0,153,173,161,128,128,0,0,45,109,164,150,98,0,0,165,114,151,108,0,0,0,0,0]},{name:'Doe',data:[1,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,2,0,0,0,0,1,0,0,0,0,0,0,0,0]})
/*end manual insert*/
/*capture to input field*/
$('#categories').val(data.Graph.Categories)
$('#series').val(data.Graph.Series)
/*JSON from struts*/
//dchart.xAxis.categories.push(data.Graph.Categories)
//dchart.series.push(data.Graph.Series)
$('#graphContainer').highcharts(dchart);
})
Response from action class
PrintWriter out = response.getWriter();
out.print("{\"Graph\":");
out.print("{");
out.print("\"Series\":\""+series+"\",\"Categories\":\""+categories+"\"");
out.print("}");
out.print("}");
response.setContentType("application/json");
JSON structure retrieve from action class as below (from firebug console)
{"Graph":
{
"Series":
"{name:'John',data:[99,155,148,136,121,0,0,153,173,161,128,128,0,0,45,109,164,150,98,0,0,165,114,151,108,0,0,0,0,0]},
{name:'Doe',data:[1,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,2,0,0,0,0,1,0,0,0,0,0,0,0,0]}"
,
"Categories":"1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30"
}
}
The problem is when I manually insert the JSON it's working fine, but json from action class display blank chart. I also capture the json from action class in the input field, the value are exactly the same like I manually hard coded.
Can somebody help me, what am I miss in my code.

Related

default value on <form:select /> is completely wrong - JSP

I'm passing an attribute "hours" containing the following values:
ArrayList<Integer> hours = new ArrayList<>(Arrays.asList({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23}));
model.addAttribute("hours", hours);
model.addAttribute("dto", dto);
on my jsp:
...
<form:select id="to" path="to" class="form-control chosen-select"
items="${hours}" value="${dto.to}" />
...
I have tried outputting the values on my jsp and they're all correct, the only problem is that they're completely wrong. dto.to should be an Integer "3" but it shows 13 as default selected value. What's the problem here??

Sorting a set using collections sort

I am trying to sort and need to retain as a set.
So, I am trying convert my Set to List and use Collections.sort and again covert back to a set but facing this error:
The method sort(List) in the type Collections is not applicable for the arguments (ArrayList)
I tried to sort using TreeSet but it sorts lexically so trying to use Collections.sort.
Set<Object> set = [11, 13, 24, 14, 25, 15, 26, 16, 27, 28, 18, 19, 1, 2, 3, 6];
ArrayList<Object> list = new ArrayList<Object>(set);
Collections.sort(list);
Where I am going wrong?
I think that using TreeSet is going to be your best option, as per the constructor documentation the default ordering is the natural ordering of the elements. With your specific pseudo-code example (using Integers) this will work pretty much perfectly:
var set1 = new TreeSet<>(Arrays.asList(
11, 13, 24, 14, 25, 15, 26, 16,
27, 28, 18, 19, 1, 2, 3, 6
));
System.out.println(set1);
[1, 2, 3, 6, 11, 13, 14, 15, 16, 18, 19, 24, 25, 26, 27, 28]
If, however, you are using Strings, then lexical ordering is used, as that's the natural ordering for that type:
var set2 = new TreeSet<>(Arrays.asList(
"11", "13", "24", "14", "25", "15", "26", "16",
"27", "28", "18", "19", "1", "2", "3", "6"
));
System.out.println(set2);
[1, 11, 13, 14, 15, 16, 18, 19, 2, 24, 25, 26, 27, 28, 3, 6]
You have the option of providing a Comparator to one of the constructors to allow you to customise the ordering to your liking:
var set3 = new TreeSet<>((String a, String b) -> {
return Integer.valueOf(a).compareTo(Integer.valueOf(b));
});
set3.addAll(Arrays.asList(
"11", "13", "24", "14", "25", "15", "26", "16",
"27", "28", "18", "19", "1", "2", "3", "6"
));
System.out.println(set3);
[1, 2, 3, 6, 11, 13, 14, 15, 16, 18, 19, 24, 25, 26, 27, 28]

MD5 generate different result between C# and Java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a byte array, and I want to compute the MD5 hash in java and C# separately. However, their generate very different result.
below is my C# code:
byte[] input = { 90, 12, 200, 139, 85, 104, 9, 202, 0, 0, 0, 0, 28, 251, 54, 201, 233, 153, 79, 1 };
MD5 md5 = MD5.Create();
byte[] result = md5.ComputeHash(input);
It generate md5 hash: 85,126,37,15,86,254,54,94,243,185,219,84,21,17,192,153,.
and below is the java code:
byte[] input = {90,12,-56,-117,85,104,9,-54,0,0,0,0,28,-5,54,-47,-23,-103,79,1};
byte[] md5 = MessageDigest.getInstance("MD5").digest(input);
and it results in:
-56,-74,-89,-76,9,35,-83,-89,-73,-39,17,83,24,18,-91,-62,
As you can see, the results are quite different. I know c# use unsigned byte, java uses signed byte. There is no way make me believe the results are identical.
Thanks in advance.
Your C# and Java inputs aren't the same.
Let's try to convert the C# input to signed bytes:
byte[] input = { 90, 12, 200, 139, 85, 104, 9, 202, 0, 0, 0, 0, 28, 251, 54, 201, 233, 153, 79, 1 };
sbyte[] signedInput = input.Select(i => unchecked((sbyte)i)).ToArray();
Console.WriteLine(string.Join(", ", signedInput));
This outputs:
90, 12, -56, -117, 85, 104, 9, -54, 0, 0, 0, 0, 28, -5, 54, -55, -23, -103, 79, 1
There's a different byte here, in bold. The Java version contains -47 at this offset.
And just to be sure, we can do a simple check using the Java version's input:
var javaInput = new[] { 90, 12, -56, -117, 85, 104, 9, -54, 0, 0, 0, 0, 28, -5, 54, -47, -23, -103, 79, 1 };
var javaInputUnsigned = javaInput.Select(i => unchecked((byte)i)).ToArray();
var hash = MD5.Create().ComputeHash(javaInputUnsigned).Select(i => unchecked((sbyte)i)).ToArray();
Console.WriteLine(string.Join(", ", hash));
This yields the same result as in the Java version:
-56, -74, -89, -76, 9, 35, -83, -89, -73, -39, 17, 83, 24, 18, -91, -62

Integer number too large in Long type variable [duplicate]

This question already has answers here:
Why is 09 "too large" of an integer number? [duplicate]
(5 answers)
Closed 7 years ago.
I tried to declare fixed array objects for testing, to remove the need to reenter objects on every run.
The array test objects are like this:
studentList[0].setStudent("Mr", "Jason", "Lee", 00001, 01, 01,2001, 85, 75, 8, 65, 72.5, "D");
studentList[1].setStudent("Miss", "Candice", "Teo", 00002, 02, 02, 2002, 95, 95, 9, 90, 92.0, "HD");
studentList[2].setStudent("Mrs", "Sophie", "Chua", 00003, 03, 03, 2003, 65, 78, 7, 92, 81.6, "HD");
studentList[3].setStudent("Mrs", "Brendon", "Low", 00004, 04, 04, 2004, 95, 98, 7, 69, 80.1, "HD");
studentList[4].setStudent("Mr", "Clarance", "Yeo", 00005, 05, 05, 2005, 80, 76, 5, 59, 65.7, "C");
studentList[5].setStudent("Mr", "Adrian", "Tan", 00006, 06, 06, 2006, 70, 60, 4, 20, 40.0, "ND");
studentList[6].setStudent("Ms", "Debbie", "Toh", 00007, 07, 07, 2007, 60, 60, 7, 50, 56.0, "P");
studentList[7].setStudent("Miss", "Sarah", "Ho", 00008, 08, 08, 2008, 59, 61, 7, 62, 62.0, "N");
studentList[8].setStudent("Mr", "Aloysius", "Lim", 00009, 09, 09, 2009, 62, 63, 8, 69, 67.5, "C");
studentList[9].setStudent("Mrs", "Peggy", "Lo", 00010, 10, 10, 2010, 65, 67, 9, 72, 71.4, "D");
They are an array object containing
studentTitle (String),
studentFirstName (String),
studentLastName (String),
studentID (Long),
and the rest are scores of (Int) and lastly gradeof (String).
However, an error was shown stating:
integer number too large: 00008
integer number too large: 08
integer number too large: 08
for both on studentList[7] and studentList[8].
May I know what should be corrected? Thank you
08 and 00008 are parsed as octal numbers, in which 8 and 9 are invalid digits. Remove the leading zeroes.

how to convert Byte code to String?

I am using a 3rd party application.
In that application, the input word "test" gets converted to byte code output.
the byte code value is appreaing as [17, 17, 17, 17, 34, 34, 34, 34, 51, 51, 51, 51, 68, 68, 68, 68]
I do not know how to convert this byte code to a readable text value (text value: "test").
I am trying this on an Android application.
Can somebody help?
Like this:
public static void main(String[] args)
{
char[] c = new char[] {17, 17, 17, 17, 34, 34, 34, 34, 51, 51, 51, 51, 68, 68, 68, 68};
String word = String.valueOf(c);
System.out.println(word);
}

Categories

Resources