How to make individual points at JChart2D? - java

I am using JChart2D for my Java desktop application and followed that example:
http://jchart2d.sourceforge.net/usage.shtml
That example makes connections between points however I need individual points.
I mean I get something like:
But I want something like:
PS: Graphic examples are different just I wanted to show difference between individual points and line between points.

Close, but no cigar. The correct API Call is:
Chart2D chart = new Chart2D();
ITrace2D trace = new Trace2DSimple();
// Add the trace to the chart:
chart.addTrace(trace);
trace.setTracePainter(new TracePainterDisc(4));
The call
trace.setTracePainter(new TracePainterDisc(4));
does the trick.

I think the answer lies in the link you posted above.
Create a trace (instance of ITrace2D) and set the PointPainter e.g. to PointPainterDisc.
Derived from the API javadoc:
Chart2D test = new Chart2D();
JFrame frame = new JFrame("Chart2D- Debug");
frame.setSize(400,200);
frame.setVisible(true);
ITrace2D atrace = new Trace2DLtd(100);
atrace.setPointHighlighter(new PointPainterDisc(5));
test.addTrace(atrace);
while(expression){
atrace.addPoint(adouble,bdouble);
....
}

trace.setTracePainter(new TracePainterDisc());

Related

How to correctly update SNMP4j agent MIB values correctly

I'm trying to create an SNMP4j agent and am finding it difficult to understand the process correctly. I have successfully created an agent that can be queried from the command line using snmpwalk. What I am having difficulty with is understanding how I am meant to update the values stored in my implemented MIB.
The following shows the relevant code I use for creating the MIB (I implement Host-Resources-MIB)
agent = new Agent("0.0.0.0/" + port);
agent.start();
agent.unregisterManagedObject(agent.getSnmpv2MIB());
modules = new Modules(DefaultMOFactory.getInstance());
HrSWRunEntryRow thisRow = modules.getHostResourcesMib().getHrSWRunEntry()
.createRow(oidHrSWRunEntry);
final OID ashEnterpriseMIB = new OID(".1.3.6.1.4.1.49266.0");
thisRow.setHrSWRunIndex(new Integer32(1));
thisRow.setHrSWRunName(new OctetString("RunnableAgent"));
thisRow.setHrSWRunID(ashEnterpriseMIB);
thisRow.setHrSWRunPath(new OctetString("All is good in the world")); // Max 128 characters
thisRow.setHrSWRunParameters(new OctetString("Everything is working")); // Max 128 characters
thisRow.setHrSWRunType(new Integer32(HrSWRunTypeEnum.application));
thisRow.setHrSWRunStatus(new Integer32(HrSWRunStatusEnum.running));
modules.getHostResourcesMib().getHrSWRunEntry().addRow(thisRow);
agent.registerManagedObject(modules.getHostResourcesMib());
This appears to be sufficient to create a runnable agent. What I do not understand is how I am meant to change the values stored in the MIB (how do I, for example, change the value of HrSWRunStatus). There seem to be a few kludge ways but they don't seem to fit with the way the library is written.
I have come across numerous references to using/overriding the methods
prepare
commit
undo
cleanup
But cannot find any examples where this is done. Any help would be gratefully received.
In protected void registerManagedObjects(), you need to do something like new MOMutableColumn(columnId, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_WRITE, null); for your HrSWRunStatus. Take a look at the TestAgent.java example of SNMP4J-agent source.

Import of custom class: several errors (e.g. java: not a statement)

I wrote a class which knows how to calculate the vector product and I want to call it in my main class. But when trying to use the class i get several Errors, that I can't explain or solve (see screenshot).
Problem_screenshot
try is keyword, you should not use it to name the variable/object.
xProduct productObj = new xProduct();
You just can not do this:
xProduct try = new xProduct();
because try is a reserved keyword in java

Crossjoin in Cascading

I'd like to crossjoin two streams of tuples in Cascading. Let's suppose there are two lists: ladies and gentlemen, and the goal is to write all the possible lady-gentleman combinations out to a file (e.g. all the possible matches from the "women seeking men" section of a hypothetical dating website).
I found a similar example on this blog and attempted to tweak the code to make a crossjoin (see https://github.com/alexwoolford/cascading-crossjoin-stackoverflow-question).
The operate method in the Crossjoin class throws a null-pointer. Firstly, the getJoinerClosure() call in this line returns null:
JoinerClosure joinerClosure = bufferCall.getJoinerClosure();
... and then the if statement that immediately follows tries to get the size of null:
if( joinerClosure.size() != 2 )
[...]
... resulting in a null-pointer exception.
Can you see where I'm going wrong?
It worked when I removed the rhsGroupFields argument from the new CoGroup constructor, i.e. changed from:
Pipe pipeLadiesAndGentlemen = new CoGroup(pipeLadies, Fields.NONE, pipeGentlemen, Fields.NONE, new Fields("lady", "gentleman"), new BufferJoin());
.. to:
Pipe pipeLadiesAndGentlemen = new CoGroup(pipeLadies, Fields.NONE, pipeGentlemen, Fields.NONE, new BufferJoin());

Getting SpooleFileList of a user in java with all the operations which we can do in as400(like view,change..etc)

I want output in the following format, which we get in as400 when WRKSPLF is executed
I am using the following code for retrieving the information from as400
try
{
AS400 as400System = new AS400();
String strSpooledFileName;
SpooledFileList splfList = new SpooledFileList(as400System);
splfList.openAsynchronously();
splfList.waitForListToComplete();
Enumeration enume= splfList.getObjects();
ArrayList<SpoolVO> list = new ArrayList<SpoolVO>();
while( enume.hasMoreElements() )
{
SpoolVO splVO = new SpoolVO();
SpooledFile splf = (SpooledFile)enume.nextElement();
if (splf != null)
{
// output this spooled file's name
splVO.setFileName(splf.getStringAttribute(SpooledFile.ATTR_SPOOLFILE));
splVO.setUserName(splf.getStringAttribute(SpooledFile.ATTR_JOBUSER));
splVO.setUserData(splf.getStringAttribute(SpooledFile.ATTR_USERDATA));
splVO.setDevice(splf.getStringAttribute(SpooledFile.ATTR_OUTPUT_QUEUE));
splVO.setTotalPages(splf.getIntegerAttribute(SpooledFile.ATTR_PAGES));
splVO.setCurrentPage(splf.getIntegerAttribute(SpooledFile.ATTR_CURPAGE));
splVO.setCopy(splf.getIntegerAttribute(SpooledFile.ATTR_COPIES));
list.add(splVO);
}
}
splfList.close();
Now by using the above code I am able to get all the fields except the Options(Opt). I want Options field in java which enables me to do all the operations like send, change, hold, etc. as specified in screenshot.
Is this possible doing with java??
Thanks in advance.
Guessing that you are using JT400 you would use SpooledFileList and SpooledFile to get the details you want. Edit your question to explain the specific details you want to retrieve. Post the code you tried.
Edit:
The Options field is not an attribute of a spooled file; you can't retrieve it from anywhere. It is a field on the display panel that lets the user request an action to be performed by the WRKSPLF command. You will need to provide that functionality within your Java program. For example, if your end user types a 3, you would issue the HLDSPLF command. If she types a 6, you would issue the RLSSPLF command.

Issues plotting multiple graphs using Java, R and JavaGD?

I have successfully drawn a single graph using Java, JavaGD and R. I followed this tutorial .
Now, I have an R-script, which reads a CSV file, does some calculations. At the end, it plots 8 different graphs. When I run this script using Java/JavaGD, only 1st and 8th plot are visible. 2nd through 7th are on "inactive" windows, which are blank. I am using the exact same code as in the above mentioned link/tutorial. So I guess something is getting overwritten.
How can I draw them on proper windows? Also, the first window, if re-sized, becomes blank. How to solve this issue?
Please don't hesitate to ask for clarification, if needed. I am not sure how well I have explained the problem.
Any help/reading material is greatly appreciated.
Update 1:
Currently, I am using this code:
public static void main(String[] args) {
// TODO Auto-generated method stub
Rengine re;
String[] dummyArgs = new String[1];
dummyArgs[0] = "--vanilla";
re = new Rengine(dummyArgs, false, null);
re.eval("library(JavaGD)");
// This is the critical line: Here, we tell R that the JavaGD() device that
// it is supposed to draw to is implemented in the class MyJavaGD. If it were
// in a package (say, my.package), this should be set to
// my/package/MyJavaGD1.
re.eval("Sys.putenv('JAVAGD_CLASS_NAME'='test/MyJavaGD1')");
re.eval("JavaGD()");
// re.eval("plot(c(1,5,3,8,5), type='l', col=2)");
// re.eval("source(\"C:\\Documents and Settings\\username\\My Documents\\Test Data\\BoxPlot.r\");");
re.eval("source(\"C:\\\\Documents and Settings\\\\username\\\\My Documents\\\\sampleRScript.R\")");
re.end();
System.out.println("Done!");
}
Part of the script:
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="1"))
boxplot(Lift ~ def, data=PlotData, main="Number 1")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
win.graph()
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="2"))
boxplot(Lift ~ def, data=PlotData, main="Number 2")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
win.graph()
par(las=2,mfrow=c(2,1))
PlotData <- subset (m4, select=c(LotNo,def,cavity,Lift), subset=(cavity=="3"))
boxplot(Lift ~ def, data=PlotData, main="Number 3")
hist(PlotData$Lift,50, main="", xlab="Lift", ylab="Frequency")
.
.
.
You'll need to tell the R instance about your initialized JRI using .jengine(), otherwise it can't issue callbacks , e.g. to resize the window. As for blanked windows you'll need to provide the code that you use.
(You may want to use stats-rosuda-devel to discuss rJava/JRI/JavaGD-related issues there.)

Categories