MPAndroid Chart connect different points on the scatterchart - java

[1
I have made a scatter plot with 3 different datasets. I want the lines between the points (in the same x-axis) to join such as to form the graph above.
This is how it looks right now, all I wanna do is to join them by a line. Is it possible with MPAndroid chart? I am currently using that library.
I tried to use combinedchart, but the result is this:

Got it! I used a candlechart. That worked like a charm. Except I just had to put my high and low values.
CandleDataSet dataSet1 = new CandleDataSet(entries,"hr");
CandleData candleData = new CandleData(time_steps,dataSet1);
candleStickChart.setData(candleData);
candleStickChart.setDrawGridBackground(false);
candleStickChart.getAxisLeft().setDrawGridLines(false);
candleStickChart.getXAxis().setDrawGridLines(false);
candleStickChart.getAxisRight().setDrawGridLines(false);
candleStickChart.setDrawBorders(false);
candleStickChart.getXAxis().setTextColor(Color.parseColor("#FFF37D63"));
candleStickChart.setBackgroundColor(Color.TRANSPARENT);
candleStickChart.getLegend().setEnabled(false);
candleStickChart.setDescription("");
candleStickChart.getAxisLeft().setTextColor(Color.parseColor("#FFF37D63"));
candleStickChart.getAxisRight().setEnabled(false);
candleStickChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
candleStickChart.setPinchZoom(false);
candleStickChart.setDoubleTapToZoomEnabled(false);

Related

JFreeChart Smudging of lines in Candlestick Chart

This has reference to JFreeChart rendering of candlestick charts. Below is the code fragment that generates a candle stick chart with JFreeChart.
This code has been tested and has been working for a long time. However, the version of JFreeChart was changed from 1.0.17 to 1.0.19 and the candlestick chart generated with 1.0.19 is showing smudging of the candle objects/lines. When I changed the library back to 1.0.17, the candlestick objects/lines once again becomes clear.
The images with both the libraries are provided below.
I have tried to find the cause of this and have been unsuccessful as yet. Now, the question is, since the code is tested and possibly does not have any error (at least what I can figure or am I missing something?), is the issue with the library? Have anyone faced this problem and has an work around
I shall be rather grateful, if someone has found the reason/solution to this and shared the same.
Please use MS Paint to view the images.
try{
chart=ChartFactory.createCandlestickChart("Candlestick Chart", "Date", "EOD Closing Price", (OHLCDataset)dataset, true);
plot=(XYPlot)chart.getPlot();
CandlestickRenderer renderer=new Chart_CandlestickRenderer();//(CandlestickRenderer)plot.getRenderer();
renderer.setSeriesPaint(0, Color.BLACK);
renderer.setUpPaint(Color.WHITE);
renderer.setDownPaint(Color.BLACK);
//HighLowItemLabelGenerator candleTooltipGenerator=new HighLowItemLabelGenerator(new SimpleDateFormat("dd-MMM-yyyy"), new DecimalFormat());
XYToolTipGenerator candleTooltipGenerator=Chart_TooltipProvider.getOHLCTooltipGenerator();
renderer.setBaseToolTipGenerator(candleTooltipGenerator);
plot.setRenderer(0,renderer);
//Organize the data to draw Fibbonacci retracements with highs and lows
DefaultOHLCDataset ohlcDataset=(DefaultOHLCDataset)dataset;
int dataCount=ohlcDataset.getItemCount(0);
data=new double[dataCount*2];//for each data item we shall get 2 values, high and low
for(int i=0;i<dataCount;i++){
//for each i 2 data values need to be put into the array and adjust the index accordingly
data[i*2]=ohlcDataset.getHighValue(0, i);
data[i*2+1]=ohlcDataset.getLowValue(0, i);
}//for closing
//If there is only the candlestick to be drawn, return, as the job has been done, draw the Fibonnaci and return
if(indicators.length==1){
this.drawFibonnaciRetracement(data, plot);
retVal=true;
return retVal;
}//if closing
}catch(Exception e){e.printStackTrace();return retVal;}
Try setting setAntiAlias of the JFreeChart to false.
JFreeChart chart = ChartFactory.createCandlestickChart(...);
chart.setAntiAlias(false);

Libgdx Table too small, does not fill viewport

I'm trying to use a Table to create a menu with lined-up Buttons and Labels. I'm using the latest nightly builds of libgdx, which changed the Table API (amongst other things).
Here's the code in my Screen constructor:
this.mStage = new Stage();
this.mTable = new Table();
this.mTable.setFillParent(true);
this.mTable.debugTable();
this.mStage.addActor(this.mTable);
// now I add some stuff to the table
// ...
My resize function looks like this:
this.mStage.setViewport(width, height, true);
this.mTable.setFillParent(true);
this.mTable.invalidate();
My render function has the following:
System.out.println("Table size is " +
this.mTable.getWidth() + " by " +
this.mTable.getHeight());
this.mStage.draw();
Table.drawDebug();
Although my console shows the correct size:
Table size is 480.0 by 640.0
the Table size is shrink-wrapped around its children, and does not extend to the correct size of 480x640.
Any ideas?
Answering my own question for the benefit of others. The way I was adding widgets to the table was incorrect:
this.mTable.row();
this.mTable.add(button).fillX();
I needed to call the fillX() method of the row():
this.mTable.row().fillX();
this.mTable.add(button);
Hope this helps someone.
To add to the above answers, it may be helpful to know that you can make these setting defaults for the table like so:
this.mTable.defaults().expandX().fillX();
The settings will apply uniformly to all rows and cells.
Your incorrect version of adding widget to the table can be easily
corrected by expanding a cell first using .expandX() method and then
by filling that cell with a widget by calling fillX().
so your initial code:
this.mTable.row();
this.mTable.add(button).fillX();
should be corrected to the following version:
this.mTable.row();
this.mTable.add(button).expandX().fillX();
these 2 lines can be shorten to one:
this.mTable.add(button).expandX().fillX().row();

How to render a 3D alien imported from Blender?

I'm getting mixed results trying to render a basic alien that was done in Blender:
I export in to Ogre 3D and load it in Eclipse:
Then when I load it in my code and try to render it the material won't render:
Could you tell me what I must do to achieve the full alien in my scene? The code I use in Jmonkeyengine is
Spatial model3 = assetManager
.loadModel("objects/creatures/alien/alien.mesh.xml");
model3.scale(0.3f, 0.3f, 0.3f);
model3.setLocalTranslation(-40.0f, 3.5f, -20.0f);
rootNode.attachChild(model3);
Update
I've got material files like these from the export:
dev#dev-OptiPlex-745:~$ ls workspace/DungeonWorld2/assets/objects/creatures/alien/
alien.mesh Material.002.material Material.005.material
alien.mesh.xml Material.003.material
alien.skeleton.xml Material.004.material
dev#dev-OptiPlex-745:~$
This material code actually produces a material in the scene but it's not the one from blender:
model3.setMaterial( new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md") );
Result:
However, loading a 3D model of an alephant without defining the material does work:
Spatial elephant = (Spatial) assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
float scale = 0.05f;
elephant.scale(scale,scale,scale);
elephant.setLocalTranslation(-50.0f, 3.5f, -20.0f);
control = elephant.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
for (String anim : control.getAnimationNames())
System.out.println("elephant can:"+anim);
The above code correctly renders the elephant so why can't I export a mesh like that for the alien? I tried to explcitly load the material but it's not working for me:
Spatial model3 = assetManager
.loadModel("objects/creatures/alien/alien.mesh.xml");
model3.scale(0.3f, 0.3f, 0.3f);
model3.setLocalTranslation(-40.0f, 3.5f, -20.0f);
model3.setMaterial( new Material(assetManager,
"objects/creatures/alien/alien.material") );
rootNode.attachChild(model3);
The above generates an exception and I don't really know what material file it is that I'm loading and what do to with the two or three other material files that the export generated:
java.lang.ClassCastException: com.jme3.material.MaterialList cannot be cast to com.jme3.material.MaterialDef
at com.jme3.material.Material.<init>(Material.java:116)
at adventure.Main.simpleInitApp(Main.java:309)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:679)
Update
Loading other models this way is working:
BlenderKey blenderKey = new BlenderKey(
"objects/creatures/troll/troll.mesh.xml");
Spatial troll = (Spatial) assetManager.loadModel(blenderKey);
troll.setLocalTranslation(new Vector3f(-145, 15, -10));
rootNode.attachChild(troll);
BlenderKey blenderKey2 = new BlenderKey(
"objects/creatures/spaceman/man.mesh.xml");
Spatial man = (Spatial) assetManager.loadModel(blenderKey2);
man.setLocalTranslation(new Vector3f(-140, 15, -10));
rootNode.attachChild(man);
I get the models inside my game and they look alreight, both the troll and the spaceman that both originally were .blend files.
Now it's much better when I did it over and it is loading the material. The only problem with the alien left now is the holes in the head that was also answered here.
BlenderKey blenderKey = new BlenderKey(
"objects/creatures/alien/alien.mesh.xml");
Spatial alien = (Spatial) assetManager.loadModel(blenderKey);
alien.setLocalTranslation(new Vector3f(-145, 15, -10));
rootNode.attachChild(alien);
You didn't write anything about your material - did you write one and used it correctly? The problem you get seems to be the lack of material to me.
In general you'll need some *.material file and probably some textures (if you used them in Blender). For the beginning you can use one of the materials that come with Ogre, you'll just need to add:
model3.setMaterialName( "Examples/Rockwall" );
Then look if it changes anything. If you still get the problem you can look into 'Ogre.log' file - it's always worth checking because all the errors goes there.
I also see the second problem here - you render the object as 'one sided' while blender probably render is as two-sided mesh, so you get the holes on the head. You can select in the material to be two sided, but it's better (and faster during rendering) to just create your models without the holes :).

jchart2D Multiple Y-axis titles grouped together

I've been using the jchart2D class by Achim Westerman for some time now and just happened upon an instance where I'm trying to make 3 Y-axes on the right hand side of my graph.
The code for making the 3 axes is as follows
//Create Y Axis 1
AAxis<IAxisScalePolicy> yAxisShaftSpeed =
new AxisLinear<IAxisScalePolicy>();
yAxisShaftSpeed.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisShaftSpeed.setMinorTickSpacing(10);
yAxisShaftSpeed.setStartMajorTick(true);
yAxisShaftSpeed.setPaintGrid(false);
yAxisShaftSpeed.setAxisTitle(new IAxis.AxisTitle("Shaft Speed (RPM)"));
IRangePolicy rangePolicyYShaftSpeed =
new RangePolicyFixedViewport(new Range(0,225));
//Create Y axis 2
AAxis<IAxisScalePolicy> yAxisWindSpeed =
new AxisLinear<IAxisScalePolicy>();
yAxisWindSpeed.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisWindSpeed.setMinorTickSpacing(10);
yAxisWindSpeed.setStartMajorTick(true);
yAxisWindSpeed.setPaintGrid(false);
yAxisWindSpeed.setAxisTitle(new IAxis.AxisTitle("Wind Speed (m/s))"));
IRangePolicy rangePolicyYWindSpeed =
new RangePolicyFixedViewport(new Range(0,25));
//Create Y axis 3
AAxis<IAxisScalePolicy> yAxisPressure =
new AxisLinear<IAxisScalePolicy>();
yAxisPressure.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisPressure.setMinorTickSpacing(10);
yAxisPressure.setStartMajorTick(true);
yAxisPressure.setPaintGrid(false);
yAxisPressure.setAxisTitle(new IAxis.AxisTitle("Pressure (hPa)"));
IRangePolicy rangePolicyYPressure =
new RangePolicyFixedViewport(new Range(700,1100));
I then go on to add and set the right hand Y axes as follows
timePlotZoomableChart.setAxisYRight(yAxisShaftSpeed,0);
timePlotZoomableChart.addAxisYRight(yAxisWindSpeed);
timePlotZoomableChart.addAxisYRight(yAxisPressure);
Unfortunately, when the graph comes up, the three Y axes are on the right as expected but all the titles are stacked up on each other under the first added right Y axis (yAxisShaftSpeed). Anyone have any thoughts?
Thanks in advance.
might be a bug (I never tested this). Feel free to post a bug report including the minimal runnable code, the version of jchart2d, the OS and java version at sourceforge.
kind regards,
Achim

Problem creating a mosaic of images using JAI

I'm trying to use JAI to create a single mosaic consisting of 4 TIF images each of which is 5000 x 5000. The code I have written is as follows ..
RenderedOp mosaic=null;
ParameterBlock pbMosaic=new ParameterBlock();
pbMosaic.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
RenderedOp in=null;
// Get 4 tiles and add them to the Mosaic
in=returnRenderedOp(path,"northwest.tif");
pbMosaic.addSource(in);
in=returnRenderedOp(path,"northeast.tif");
pbMosaic.addSource(in);
in=returnRenderedOp(path,"southwest.tif");
pbMosaic.addSource(in);
in=returnRenderedOp(path,"southeast.tif");
pbMosaic.addSource(in);
// Setup the ImageLayout
ImageLayout imageLayout=new ImageLayout(0,0,10000,10000);
imageLayout.setTileWidth(5000);
imageLayout.setTileHeight(5000);
imageLayout.setColorModel(in.getColorModel());
imageLayout.setSampleModel(in.getSampleModel());
mosaic=JAI.create("mosaic",pbMosaic,new RenderingHints(JAI.KEY_IMAGE_LAYOUT,imageLayout));
The problem is that all 4 images are being positioned in the same place in the top left hand corner of the mosaic so the other three quarters of it is empty. Can anyone tell me how I can choose the position of each picture that makes up the mosaic so each appears in the correct place ?
Thanks
Ian
http://download.oracle.com/docs/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MosaicDescriptor.html
I think you misunderstood the doc you need to set the minX minY for EACH source image before the operation.
northwest.tif should have minX=0 and minY=0,
northeast.tif should have minX=5000 and minY=0,
southwest.tif should have minX=0, minY=5000 and
southeast.tif should have minx=5000 and minY = 5000
In the doc they suggest you deserialize the files directly "moved" by using rendering hint on the deserialization operation.
Somehow, mosaic is just a normal compositing operation.

Categories