利用者:Truesight

日本の影響力について(2012 BBC Poll[1])
肯定的
否定的
ナイジェリア
80
10
インドネシア
77
5
アメリカ
74
18
カナダ
72
16
イギリス
70
17
ケニア
68
15
フランス
66
24
オーストラリア
65
23
スペイン
62
17
ブラジル
60
22
ドイツ
58
29
チリ
57
12
ペルー
57
14
エジプト
57
15
ロシア
54
10
ガーナ
48
10
インド
44
11
メキシコ
44
26
日本
41
9
パキスタン
41
17
韓国
38
58
中国
16
63

BBC Global Poll 2012[2]からグラフを作成してみました。javaでプログラムを作成。引数を与えると 適当に大きさや色を変えられます。ソースは一番下(→色々変更したから結構グダグダ)。

Views of Japan's influence By country 2012.

java make_table 60 11 7 3 #5555ff #ff7766

タイトル幅:60 / 高さ:11 / フォントサイズ:7 / 幅倍率:3 / 色1:#5555ff / 色2:#ff7766

ナイジェリア
80
10
インドネシア
77
5
アメリカ
74
18
カナダ
72
16
イギリス
70
17
ケニア
68
15
フランス
66
24
オーストラリア
65
23
スペイン
62
17
ブラジル
60
22
ドイツ
58
29
チリ
57
12
ペルー
57
14
エジプト
57
15
ロシア
54
10
ガーナ
48
10
インド
44
11
メキシコ
44
26
日本
41
9
パキスタン
41
17
韓国
38
58
中国
16
63

java make_table 60 11 7 3 #3333ff #ff7744

タイトル幅:60 / 高さ:11 / フォントサイズ:7 / 幅倍率:3 / 色1:#3333ff / 色2:#ff7744

ナイジェリア
80
10
インドネシア
77
5
アメリカ
74
18
カナダ
72
16
イギリス
70
17
ケニア
68
15
フランス
66
24
オーストラリア
65
23
スペイン
62
17
ブラジル
60
22
ドイツ
58
29
チリ
57
12
ペルー
57
14
エジプト
57
15
ロシア
54
10
ガーナ
48
10
インド
44
11
メキシコ
44
26
日本
41
9
パキスタン
41
17
韓国
38
58
中国
16
63


java make_table 100 14 11 5 #4444ff #ff8844

タイトル幅:100 / 高さ:14 / フォントサイズ:11 / 幅倍率:5 / 色1:#4444ff / 色2:#ff8844

ナイジェリア
80
10
インドネシア
77
5
アメリカ
74
18
カナダ
72
16
イギリス
70
17
ケニア
68
15
フランス
66
24
オーストラリア
65
23
スペイン
62
17
ブラジル
60
22
ドイツ
58
29
チリ
57
12
ペルー
57
14
エジプト
57
15
ロシア
54
10
ガーナ
48
10
インド
44
11
メキシコ
44
26
日本
41
9
パキスタン
41
17
韓国
38
58
中国
16
63


※閲覧モードでは改行されないため、編集モードで呼んでください。

ぐだぐだです。面倒くさくなったので本来外付けすべきパラメータもハードコーディングしてます。 データはdata.txtにCSV形式で置いてください。 こんな感じ↓ 【data.txt】 ナイジェリア 80 10 インドネシア 77 5 アメリカ 74 18 カナダ 72 16 イギリス 70 17 ケニア 68 15 フランス 66 24 オーストラリア 65 23 スペイン 62 17 ブラジル 60 22 ドイツ 58 29 チリ 57 12 ペルー 57 14 エジプト 57 15 ロシア 54 10 ガーナ 48 10 インド 44 11 メキシコ 44 26 日本 41 9 パキスタン 41 17 韓国 38 58 中国 16 63

引数の指定方法は、 java make_table 100 14 11 5 #4444ff #ff8844 で、タイトル幅:100 / 高さ:14 / フォントサイズ:11 / 幅倍率:5 / 色1:#4444ff / 色2:#ff8844

【make_table_b.java】 import java.io.*; import java.util.*; public class make_table_b { static private String data[] = new String[10]; static private String header[] = { "{| class=\"wikitable\" style=\"border:1px black; float:right; margin-left:1em;\"", "|-", "|<div style=\"width:<<table_width>>px;height:<<table_name_height>>px;font:<<table_name_font_size>>pt 'Meiryo';text-align:center\"><<table_name>></div>", }; static private String footer[] = { "|}", }; static private String label[] = { "{|", "|-", "|<div style=\"width:<<title_width>>px;height:<<height>>px;font:<<font_size>>pt 'Meiryo'\"></div>", "|<div style=\"width:<<label_col_size>>px;height:<<height>>px;background:<<color_1>>;text-align:center;font:<<font_size>>pt 'Times New Roman';color:#000000\"></div>", "|<div style=\"width:<<label_size>>px;height:<<height>>px;font:<<font_size>>pt 'Meiryo'\"><<label_1>></div>", "|<div style=\"position:relative;left:<<label_space>>px;width:<<label_col_size>>px;height:<<height>>px;background:<<color_2>>;text-align:center;font:<<font_size>>pt 'Times New Roman';color:#000000\"></div>", "|<div style=\"position:relative;left:<<label_space>>px;width:<<label_size>>px;height:<<height>>px;font:<<font_size>>pt 'Meiryo'\"><<label_2>></div>", "|}", }; static private String template[] = { "{|", "|-", "|<div style=\"width:<<title_width>>px;height:<<height>>px;font:<<font_size>>pt 'Meiryo'\"><<title>></div>", "|<div style=\"width:<<val1_m>>px;height:<<height>>px;background:<<color_1>>;text-align:center;font:<<font_size>>pt 'Times New Roman';color:<<font_color_1>>\"><<val1>></div>", "|<div style=\"position:relative;left:<<space>>px;width:<<val2_m>>px;height:<<height>>px;background:<<color_2>>;text-align:center;font:<<font_size>>pt 'Times New Roman';color:<<font_color_2>>\"><<val2>></div>", "|}", }; static private String d2 (String s) { return (s.length () < 2 ? "0" + s : s); } // NTSC加重平均から適当に反色を白黒二値で返す static private String get_color_x (String s) { int i = 2 * (Integer.parseInt (s.substring (1, 3), 16) + 4 * Integer.parseInt (s.substring (3, 5), 16) + Integer.parseInt (s.substring (5, 7), 16)) / 7; if (i > 200) return "#000000"; return "#ffffff"; } static private void read_data () { File inputFile = null; FileReader in = null; BufferedReader br = null; try { inputFile = new File("data.txt"); in = new FileReader(inputFile); br = new BufferedReader(in); ArrayList<String> al = new ArrayList<String> (); String s; while ((s = br.readLine()) != null) { byte b[] = s.getBytes (); int bi = 0; int i = 0; for (i = 0; i < b.length; i++) { if (b[i] == (byte)'\t') { al.add (new String (b, bi, i - bi)); bi = ++i; } } al.add (new String (b, bi, i - bi)); } data = al.toArray (data); } catch (Exception e) { e.printStackTrace (); } finally { try { br.close(); in.close(); } catch (IOException ex) { ex.printStackTrace(); } } } static public void main (String args[]) { read_data (); int title_width = 80; int height = 16; int font_size = 6; int factor = 4; String color_1 = "#9999ff"; String color_2 = "#ff9999"; if (args.length > 0) { System.out.print ("java make_table "); for (int i = 0; i < args.length; i++) System.out.print (" " + args[i]); System.out.println (""); System.out.println (""); try { int i = 0; title_width = Integer.parseInt (args[i++]); height = Integer.parseInt (args[i++]); font_size = Integer.parseInt (args[i++]); factor = Integer.parseInt (args[i++]); color_1 = args[i++]; color_2 = args[i++]; } catch (Exception e) { System.err.println ("err."); System.exit (1); } } System.out.print ("タイトル幅:" + title_width); System.out.print (" / 高さ:" + height); System.out.print (" / フォントサイズ:" + font_size); System.out.print (" / 幅倍率:" + factor); System.out.print (" / 色1:" + color_1); System.out.print (" / 色2:" + color_2); System.out.println (""); String font_color_1 = get_color_x (color_1); String font_color_2 = get_color_x (color_2); // output table_header for (int j = 0; j < header.length; j++) { String s = header[j]; s = s.replaceAll ("<<table_width>>", "" + (title_width + factor * 100 + 20)); s = s.replaceAll ("<<table_name_height>>", "" + 24); s = s.replaceAll ("<<table_name_font_size>>", "" + 11); s = s.replaceAll ("<<table_name>>", "日本の影響力(2012 BBC Poll<ref>http://www.globescan.com/images/images/pressreleases/bbc2012_country_ratings/2012_bbc_country%20rating%20final%20080512.pdf</ref>)"); System.out.println (s); } //output_label for (int j = 0; j < label.length; j++) { String s = label[j]; s = s.replaceAll ("<<title_width>>", "" + title_width); s = s.replaceAll ("<<height>>", "" + height); s = s.replaceAll ("<<font_size>>", "" + font_size); s = s.replaceAll ("<<color_1>>", color_1); s = s.replaceAll ("<<color_2>>", color_2); s = s.replaceAll ("<<label_1>>", "肯定的"); s = s.replaceAll ("<<label_2>>", "否定的"); s = s.replaceAll ("<<label_space>>", "" + 50 * factor); s = s.replaceAll ("<<label_col_size>>", "" + 20); s = s.replaceAll ("<<label_size>>", "" + 60); System.out.println (s); } for (int i = 0; i < data.length; i += 3) { for (int j = 0; j < template.length; j++) { String s = template[j]; int v1 = Integer.parseInt (data[i + 1]); int v2 = Integer.parseInt (data[i + 2]); s = s.replaceAll ("<<title_width>>", "" + title_width); s = s.replaceAll ("<<height>>", "" + height); s = s.replaceAll ("<<font_size>>", "" + font_size); s = s.replaceAll ("<<font_color_1>>", font_color_1); s = s.replaceAll ("<<font_color_2>>", font_color_2); s = s.replaceAll ("<<color_1>>", color_1); s = s.replaceAll ("<<color_2>>", color_2); s = s.replaceAll ("<<title>>", data[i]); s = s.replaceAll ("<<val1>>", data[i + 1]); s = s.replaceAll ("<<val2>>", data[i + 2]); s = s.replaceAll ("<<val1_m>>", ("" + v1 * factor)); s = s.replaceAll ("<<space>>", ("" + (100 - v1 - v2) * factor)); s = s.replaceAll ("<<val2_m>>", ("" + v2 * factor)); System.out.println (s); } } for (int j = 0; j < footer.length; j++) { String s = footer[j]; System.out.println (s); } } }


  1. ^ http://www.globescan.com/images/images/pressreleases/bbc2012_country_ratings/2012_bbc_country%20rating%20final%20080512.pdf
  2. ^ http://www.globescan.com/images/images/pressreleases/bbc2012_country_ratings/2012_bbc_country%20rating%20final%20080512.pdf