D3.js

LEUNG    D3.js 沒有迴響

d3.js

D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.

Reference : https://d3js.org/

Post JSON to web api in PHP

[Action] POST JSON format

{
    "command": "login",
    "params": {
        "username": "username",
        "password": "password"
    }
}

[Action] Return POST result

{
    "success": true
}

index.php

$data = array(
  'command' => 'login',
  'params' => array(
        'username' => 'username',
        'password' => 'password'    
  )
);
json_encode( $data );

$api_url = 'https://study.ar-leung.net';
$ch = curl_init( $api_url );

# Setup request to send json via POST.
$payload = json_encode( $data );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

# Send request.
$result = curl_exec($ch);
curl_close($ch);

# Print response.
echo "<pre>$result</pre>";

$json_data = json_decode($result);
echo $json_data->success;

Add back button in title bar – android

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Button;

public class Transaction extends AppCompatActivity {

    private Button btn_back;
    Intent intent = new Intent();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transaction);

        // Set title bar
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    // Back to page method 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if(id == android.R.id.home){
            intent.setClass(Transaction.this, MainActivity.class);
            startActivity(intent);
            Transaction.this.finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Add-back-button-in-title-bar