<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>迷途知返</title>
	<atom:link href="http://pwwang.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pwwang.com</link>
	<description>专注技术,用心生活!</description>
	<lastBuildDate>Fri, 02 Jul 2010 02:26:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>linux下列举特定时间段文件的命令</title>
		<link>http://pwwang.com/technology/linux/linux_ls_time_limit/</link>
		<comments>http://pwwang.com/technology/linux/linux_ls_time_limit/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 09:24:07 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=951</guid>
		<description><![CDATA[&#160;我们知道在linux下，ls，或者ll（ls -l）可以列出目录下的文件，加上grep可以对文件名进行过滤

可以如果我们要列出特定时间段创建的文件呢？

让awk大发神威吧。

<span class="readmore"><a href="http://pwwang.com/technology/linux/linux_ls_time_limit/" title="linux下列举特定时间段文件的命令">Read More: 171 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;我们知道在linux下，ls，或者ll（ls -l）可以列出目录下的文件，加上grep可以对文件名进行过滤</p>
<p>可以如果我们要列出特定时间段创建的文件呢？</p>
<p>让awk大发神威吧。</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #660033;">--time-style</span>=+<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'$6 &gt; &quot;201006241251&quot;'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'$6 &lt; &quot;201006241255&quot;'</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>不得不说， 需要灵活的头脑啊！</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/linux/linux_ls_time_limit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>asp分页类</title>
		<link>http://pwwang.com/technology/asp/asp_pagination_class/</link>
		<comments>http://pwwang.com/technology/asp/asp_pagination_class/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 12:36:09 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[分页]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=939</guid>
		<description><![CDATA[&#160;

效果图：



<span class="readmore"><a href="http://pwwang.com/technology/asp/asp_pagination_class/" title="asp分页类">Read More: 4138 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>效果图：</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/06/pagination.jpg"><img width="561" height="287" border="0" title="pagination" src="http://pwwang.com/wp-content/uploads/2010/06/pagination.jpg" style="clear: both;" alt="" /></a></p>
<p><span id="more-939"></span>调用：</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;65001&quot;%&gt;
&lt;!--#include file=&quot;access.class.asp&quot;--&gt;
&lt;!--#include file=&quot;pagination.class.asp&quot;--&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;
&lt;title&gt;无标题文档&lt;/title&gt;
&lt;link href=&quot;pagination.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;%
function len1(a)
len1 = left(a,10) &amp; &quot;...&quot;
end function
&nbsp;
set p = new Pagination
p.template=&quot;{{title|len1}}&quot;
p.sql = &quot;select * from News&quot;
p.pkey = &quot;id&quot;
p.cols = 2
p.page = request.QueryString(&quot;page&quot;)
p.show
%&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>&nbsp;</p>
<p>类代码：</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">&lt;%
<span style="color: #008000;">''''''''''''''''''''''''''''''''
</span><span style="color: #008000;">'                              '
</span><span style="color: #008000;">' Author: pwwang               '
</span><span style="color: #008000;">' Site  : http://pwwang.com    '
</span><span style="color: #008000;">' Version: 1.0                 '
</span><span style="color: #008000;">'                              '
</span><span style="color: #008000;">''''''''''''''''''''''''''''''''
</span>
class Pagination
    <span style="color: #000080;">private</span> pSql
    <span style="color: #000080;">private</span> pHeader
    <span style="color: #000080;">private</span> pFooter
    <span style="color: #000080;">private</span> pTemplate
    <span style="color: #000080;">private</span> pRows
    <span style="color: #000080;">private</span> pCols
    <span style="color: #000080;">private</span> pPage
    <span style="color: #000080;">private</span> pPKey
&nbsp;
    <span style="color: #000080;">private</span> pPageCount
    <span style="color: #000080;">private</span> pRecordCount
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> pkey(value)
        pPKey = value
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> page(value)
        pPage = value
        <span style="color: #000080;">if</span> <span style="color: #000080;">not</span> isNumeric(pPage) <span style="color: #000080;">then</span> pPage = 1
        <span style="color: #000080;">if</span> pPage &lt; 1 <span style="color: #000080;">then</span> pPage = 1
        pPage = <span style="color: #000080;">cint</span>(pPage)
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> sql(value)
        pSql = value
        db.query(value)
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> header(value)
        pHeader = value
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> footer(value)
        pFooter = value
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> template(value)
        pTemplate = value
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> rows(value)
        pRows = value
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">property</span> <span style="color: #000080;">let</span> cols(value)
        pCols = value
    <span style="color: #000080;">end</span> <span style="color: #000080;">property</span>
&nbsp;
    <span style="color: #000080;">private</span> <span style="color: #000080;">function</span> tempcode(i)
        <span style="color: #000080;">dim</span> t, re, re1, matches, mat, mat1, datandfun, data, fun
        <span style="color: #000080;">set</span> re = <span style="color: #000080;">new</span> RegExp
        <span style="color: #000080;">set</span> re1 = <span style="color: #000080;">new</span> RegExp
        t = pTemplate
&nbsp;
        re.Pattern=<span style="color: #800000;">&quot;\{\{\s*[^}]+\s*\}\}&quot;</span>
        re.global = <span style="color: #000080;">true</span>
        <span style="color: #000080;">set</span> matches = re.execute(t)
&nbsp;
        <span style="color: #000080;">for</span> <span style="color: #000080;">each</span> mat <span style="color: #000080;">in</span> matches
            mat1 = trim(mid(mat,3,len(mat)-4))
            datandfun = split(mat1, <span style="color: #800000;">&quot;|&quot;</span>)
            <span style="color: #000080;">if</span> <span style="color: #000080;">Ubound</span>(datandfun) = 0 <span style="color: #000080;">then</span>
                data = trim(mat1)
                t = replace(t, mat, db.get_value2(data,i))
            <span style="color: #000080;">else</span>
                data = trim(datandfun(0))
                fun  = trim(datandfun(1))
                t = replace(t, mat, eval( fun &amp; <span style="color: #800000;">&quot;(&quot;</span><span style="color: #800000;">&quot;&quot;</span> &amp; db.get_value2(data, i) &amp; <span style="color: #800000;">&quot;&quot;</span><span style="color: #800000;">&quot;)&quot;</span>))
            <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
        <span style="color: #000080;">next</span>
        tempcode = t
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">private</span> <span style="color: #000080;">function</span> getFooter()
        <span style="color: #000080;">if</span> <span style="color: #000080;">not</span> pFooter <span style="color: #000080;">then</span>
            getFooter = <span style="color: #800000;">&quot;&quot;</span>
        <span style="color: #000080;">else</span>
            getFooter = <span style="color: #800000;">&quot;&lt;table width='100%' border='0' id='pagination_footer'&gt;&quot;</span>
            getFooter = getFooter &amp; <span style="color: #800000;">&quot;&lt;tr&gt;&lt;td&gt;&quot;</span>
            getFooter = getFooter &amp; <span style="color: #800000;">&quot; 当前页:&quot;</span> &amp; pPage &amp; <span style="color: #800000;">&quot;/&quot;</span> &amp; pPageCount
            getFooter = getFooter &amp; <span style="color: #800000;">&quot; 记录数:&quot;</span> &amp; pRecordCount
            <span style="color: #000080;">if</span> pPage &gt; 1 <span style="color: #000080;">then</span>
                getFooter = getFooter &amp; <span style="color: #800000;">&quot; &lt;a href='?page=1'&gt;首页&lt;/a&gt; &lt;a href='?page=&quot;</span> &amp; pPage - 1 &amp;<span style="color: #800000;">&quot;'&gt;上页&lt;/a&gt; &quot;</span>
            <span style="color: #000080;">else</span>
                getFooter = getFooter &amp; <span style="color: #800000;">&quot; 首页 上页 &quot;</span>
            <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
            <span style="color: #000080;">if</span> pPage &lt; pPageCount <span style="color: #000080;">then</span>
                getFooter = getFooter &amp; <span style="color: #800000;">&quot; &lt;a href='?page=&quot;</span> &amp; pPage + 1 &amp;<span style="color: #800000;">&quot;'&gt;下页&lt;/a&gt; &lt;a href='?page=&quot;</span> &amp; pPageCount &amp; <span style="color: #800000;">&quot;'&gt;尾页&lt;/a&gt; &quot;</span>
            <span style="color: #000080;">else</span>
                getFooter = getFooter &amp; <span style="color: #800000;">&quot; 下页 尾页 &quot;</span>
            <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
            getFooter = getFooter &amp; <span style="color: #800000;">&quot; 跳到第&lt;input type='text' id='gotopage' size='1' value='&quot;</span>&amp;pPage&amp;<span style="color: #800000;">&quot;' /&gt;页&lt;input type='button' value='Go' onclick=&quot;</span><span style="color: #800000;">&quot;javascript:location='?page='+document.getElementById('gotopage').value&quot;</span><span style="color: #800000;">&quot; /&gt;&quot;</span>
            getFooter = getFooter &amp; <span style="color: #800000;">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</span>
        <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">private</span> <span style="color: #000080;">function</span> mainloop()
        <span style="color: #000080;">if</span> isempty(pFooter) <span style="color: #000080;">then</span> pFooter = <span style="color: #000080;">true</span>
        <span style="color: #000080;">if</span> isempty(pRows) <span style="color: #000080;">then</span> pRows = 10
        <span style="color: #000080;">if</span> isempty(pCols) <span style="color: #000080;">then</span> pCols = 1
&nbsp;
        pRecordCount = db.num_rows
        pPageCount = <span style="color: #000080;">cint</span>(pRecordCount / (pRows * pCols) + 0.5)
        <span style="color: #000080;">if</span> pPage &gt; pPageCount <span style="color: #000080;">then</span> pPage = pPageCount
&nbsp;
        <span style="color: #000080;">dim</span> pagesql, startr, endr
        startr  = (pPage - 1) * pRows * pCols
        <span style="color: #000080;">if</span> pPage * pRows * pCols &gt; pRecordCount <span style="color: #000080;">then</span>
            endr = pRecordCount
        <span style="color: #000080;">else</span>
            endr = pPage * pRows * pCols
        <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>            
        <span style="color: #000080;">if</span> pPage &gt; 1 <span style="color: #000080;">then</span>
            pagesql = <span style="color: #800000;">&quot;SELECT TOP &quot;</span> &amp; endr &amp; <span style="color: #800000;">&quot; * FROM (&quot;</span> &amp; pSql &amp; <span style="color: #800000;">&quot;) WHERE &quot;</span> &amp; pPKey &amp; <span style="color: #800000;">&quot; NOT IN (SELECT TOP &quot;</span> &amp; startr &amp; <span style="color: #800000;">&quot; &quot;</span> &amp; pPKey &amp; <span style="color: #800000;">&quot; FROM (&quot;</span> &amp; pSql &amp; <span style="color: #800000;">&quot;))&quot;</span>
        <span style="color: #000080;">else</span>
            pagesql = <span style="color: #800000;">&quot;SELECT TOP &quot;</span> &amp; pRows * pCols &amp; <span style="color: #800000;">&quot; * FROM (&quot;</span> &amp; pSql &amp; <span style="color: #800000;">&quot;)&quot;</span>
        <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
&nbsp;
        db.query(pagesql)
&nbsp;
        <span style="color: #000080;">dim</span> i, j
        mainloop = <span style="color: #800000;">&quot;&lt;table width='100%' border='0' cellspacing='1' id='pagination_table'&gt;&quot;</span>
        <span style="color: #000080;">for</span> i = 0 <span style="color: #000080;">to</span> pRows - 1
            <span style="color: #000080;">if</span> i <span style="color: #000080;">mod</span> 2 = 0 <span style="color: #000080;">then</span>
                mainloop = mainloop &amp; <span style="color: #800000;">&quot;&lt;tr class='odd'&gt;&quot;</span>
            <span style="color: #000080;">else</span> 
                mainloop = mainloop &amp; <span style="color: #800000;">&quot;&lt;tr class='even'&gt;&quot;</span>
            <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
            <span style="color: #000080;">for</span> j = 0 <span style="color: #000080;">to</span> pCols - 1
                mainloop = mainloop &amp; <span style="color: #800000;">&quot;&lt;td&gt;&quot;</span>
                <span style="color: #000080;">if</span> i*pCols+j &lt; db.num_rows <span style="color: #000080;">then</span>
                    mainloop = mainloop &amp; tempcode(i*pCols+j)
                <span style="color: #000080;">else</span> 
                    mainloop = mainloop &amp; <span style="color: #800000;">&quot; &quot;</span>
                <span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
                mainloop = mainloop &amp; <span style="color: #800000;">&quot;&lt;/td&gt;&quot;</span>
            <span style="color: #000080;">next</span>
            mainloop = mainloop &amp; <span style="color: #800000;">&quot;&lt;/tr&gt;&quot;</span>
        <span style="color: #000080;">next</span>
        mainloop = mainloop &amp; <span style="color: #800000;">&quot;&lt;/table&gt;&quot;</span>
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">sub</span> show()
        response.write pHeader
        response.write mainloop
        response.write getFooter
    <span style="color: #000080;">end</span> <span style="color: #000080;">sub</span>
&nbsp;
<span style="color: #000080;">end</span> class
&nbsp;
%&gt;</pre></td></tr></table></div>

<p>&nbsp;</p>
<p>CSS:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#pagination_table</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#09F</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#pagination_table</span> td<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#pagination_table</span> tr.odd<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#pagination_table</span> tr.even<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#pagination_footer</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>说明：</p>
<p>1. 需要调用之前发布的<a href="http://pwwang.com/technology/asp/%e7%ba%af%e5%b1%9e%e6%97%a0%e8%81%8aasp-access%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e7%b1%bb/">access操作类</a></p>
<p>2. 可以分列，单页记录数为rows和cols决定</p>
<p>3. 表头由参数header直接给出</p>
<p>4. 参数footer决定是否显示表脚（翻页链接）</p>
<p>5. {{parm}}用来显示数据库中这个列名对应的数据</p>
<p>6. {{parm|fun}}fun函数可以对这个数据进行修饰</p>
<p>7. 表的样式可以通过css定义，奇偶行可以定义不同的样式</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/asp/asp_pagination_class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[纯属无聊]asp access数据库操作类</title>
		<link>http://pwwang.com/technology/asp/%e7%ba%af%e5%b1%9e%e6%97%a0%e8%81%8aasp-access%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e7%b1%bb/</link>
		<comments>http://pwwang.com/technology/asp/%e7%ba%af%e5%b1%9e%e6%97%a0%e8%81%8aasp-access%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e7%b1%bb/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 12:30:42 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[ASP]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=937</guid>
		<description><![CDATA[调用：



1

<span class="readmore"><a href="http://pwwang.com/technology/asp/%e7%ba%af%e5%b1%9e%e6%97%a0%e8%81%8aasp-access%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e7%b1%bb/" title="[纯属无聊]asp access数据库操作类">Read More: 1352 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>调用：</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">db.query(<span style="color: #800000;">&quot;select * from News&quot;</span>)
rs = db.fetch_all
<span style="color: #000080;">for</span> i=0 <span style="color: #000080;">to</span> db.num_rows - 1
    response.write rs(1,i) &amp; <span style="color: #800000;">&quot;&lt;br&gt;&quot;</span>
<span style="color: #000080;">next</span>
&nbsp;
db.query(<span style="color: #800000;">&quot;select * from admin&quot;</span>)
response.write db.get_value(<span style="color: #800000;">&quot;id&quot;</span>)</pre></td></tr></table></div>

<p><span id="more-937"></span></p>
<p>类代码：</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">&lt;%
class DBConn
    <span style="color: #000080;">private</span> conn
    <span style="color: #000080;">private</span> rs
&nbsp;
    <span style="color: #000080;">private</span> <span style="color: #000080;">sub</span> Class_Initialize
        <span style="color: #000080;">Set</span> conn = Server.CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
        <span style="color: #000080;">set</span> rs = Server.CreateObject(<span style="color: #800000;">&quot;adodb.recordset&quot;</span>)
    <span style="color: #000080;">end</span> <span style="color: #000080;">sub</span>
&nbsp;
    <span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Class_Terminate
        rs.<span style="color: #000080;">close</span>
        <span style="color: #000080;">set</span> rs = <span style="color: #000080;">nothing</span>
        conn.<span style="color: #000080;">close</span>
        <span style="color: #000080;">set</span> conn = <span style="color: #000080;">nothing</span>
    <span style="color: #000080;">end</span> <span style="color: #000080;">sub</span>
&nbsp;
    <span style="color: #000080;">private</span> <span style="color: #000080;">function</span> indexOfCols(colname)
        <span style="color: #000080;">dim</span> i
        <span style="color: #000080;">for</span> i = 0 <span style="color: #000080;">to</span> rs.fields.count - 1
            <span style="color: #000080;">if</span> rs(i).name = colname <span style="color: #000080;">then</span>
                indexOfCols = i
                <span style="color: #000080;">exit</span> <span style="color: #000080;">function</span>
            <span style="color: #000080;">end</span> <span style="color: #000080;">if</span> 
        <span style="color: #000080;">Next</span>
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">sub</span> query(sql)
        <span style="color: #000080;">if</span> rs.state = 1 <span style="color: #000080;">then</span> rs.<span style="color: #000080;">close</span>
        rs.<span style="color: #000080;">open</span> sql,conn,1,3
    <span style="color: #000080;">end</span> <span style="color: #000080;">sub</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> get_value(colname)
        get_value = rs(colname) 
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> get_value2(colname, row)
        <span style="color: #000080;">dim</span> rows
        rs.movefirst
        rows = rs.getrows()
        get_value2 = rows(indexOfCols(colname), row)
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> get_value3(col, row)
        <span style="color: #000080;">dim</span> rows
        rs.movefirst
        rows = rs.getrows()
        get_value3 = rows(col, row)
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> fetch_array()
        <span style="color: #000080;">redim</span> ret(rs.fields.count)
        <span style="color: #000080;">dim</span> i
        <span style="color: #000080;">for</span> i=0 <span style="color: #000080;">to</span> <span style="color: #000080;">ubound</span>(ret) - 1
            ret(i) = rs(i)
        <span style="color: #000080;">next</span>
        fetch_array = ret
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> num_rows()
        num_rows = rs.recordcount
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> fetch_all()
        rs.movefirst
        fetch_all = rs.getrows()
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">function</span> num_fields()
        num_fields = rs.fields.count
    <span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
&nbsp;
    <span style="color: #000080;">public</span> <span style="color: #000080;">sub</span> <span style="color: #000080;">open</span>(connstr)
        conn.<span style="color: #000080;">open</span> connstr
    <span style="color: #000080;">end</span> <span style="color: #000080;">sub</span>
&nbsp;
<span style="color: #000080;">end</span> class
&nbsp;
<span style="color: #000080;">dim</span> db
<span style="color: #000080;">set</span> db = <span style="color: #000080;">new</span> DBConn
db.<span style="color: #000080;">open</span> <span style="color: #800000;">&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;</span> &amp; Server.MapPath(<span style="color: #800000;">&quot;#db.mdb&quot;</span>)
&nbsp;
%&gt;</pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/asp/%e7%ba%af%e5%b1%9e%e6%97%a0%e8%81%8aasp-access%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e7%b1%bb/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[8]：饼图的图例</title>
		<link>http://pwwang.com/technology/python/pychartdirector8/</link>
		<comments>http://pwwang.com/technology/python/pychartdirector8/#comments</comments>
		<pubDate>Tue, 18 May 2010 02:13:24 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=933</guid>
		<description><![CDATA[&#160;

上节我们说了标签，这节我们来说图例：

先看图

<span class="readmore"><a href="http://pwwang.com/technology/python/pychartdirector8/" title="PyChartDirector中文教程[8]：饼图的图例">Read More: 3789 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>上节我们说了标签，这节我们来说图例：</p>
<p>先看图</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/legendpie.png"><img width="300" height="180" border="0" title="legendpie" src="http://pwwang.com/wp-content/uploads/2010/05/legendpie-300x180.png" style="clear: both;" alt="" /></a></p>
<p><span id="more-933"></span>这个例子不仅展示了图例的显示，也展示了标签的样式的设定和饼图边缘阴影化。</p>
<p>－图例增加通过：BaseChart.addLegend</p>
<p>－改变标签样式使用：<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">PieChart.setLabelFormat</span></span></p>
<p>－增加边缘阴影：<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">PieChart.setSectorStyle</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">代码：</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">35</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>,
    <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 450 x 270 pixels</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">450</span>, <span style="color: #ff4500;">270</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (150, 100) and the radius to 80 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">135</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># add a legend box where the top left corner is at (330, 50)</span>
c.<span style="color: black;">addLegend</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">330</span>, <span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># modify the sector label format to show percentages only</span>
c.<span style="color: black;">setLabelFormat</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;{percent}%&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use rounded edge shading, with a 1 pixel white (FFFFFF) border</span>
c.<span style="color: black;">setSectorStyle</span><span style="color: black;">&#40;</span>RoundedEdgeShading, 0xffffff, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;legendpie.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p></span></span></p>
<p>我们再来看看更为复杂一点的图例：</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/legendpie2.png"><img width="300" height="162" border="0" title="legendpie2" src="http://pwwang.com/wp-content/uploads/2010/05/legendpie2-300x162.png" style="clear: both;" alt="" /></a></p>
<p>我们看看这张图有些什么效果：背景颜色渐变、圆角图例框、软阴影、自定义区域颜色、区域阴影渐变、用CDML自定义区域标签、格式化的图例文字</p>
<p>－背景颜色渐变：BaseChart.linearGradientColor</p>
<p>－圆角图例框：BaseChart.setRoundedFrame</p>
<p>－软阴影：BaseChart.setDropShadow</p>
<p>－区域自定义颜色：BaseChart.setColors</p>
<p>－区域渐变阴影：PieChart.setSectorStyle</p>
<p>－自定义区域标签：PieChart.setLabelFormat（设置序号）、PieChart.setLabelStyle（设置样式）、Box.setBackground（标签加框）</p>
<p>－图例文字设置：用LegendBox的TextBox.setText，图例文字模板是用如下CDML描述的：</p>
<blockquote>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: 'courier new',courier; font-size: 13px;" class="Apple-style-span">&lt;*block,valign=top*&gt;{={sector}+1}.&lt;*advanceTo=22*&gt;&lt;*block,width=120*&gt;{label}&lt;*/*&gt;&lt;*block,width=40,halign=right*&gt;{percent}&lt;*/*&gt;%</span></span></p>
</blockquote>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: 'courier new',courier; font-size: 13px;" class="Apple-style-span">&lt;*block,valign=top*&gt; 表示图例中不同的部分都顶端对齐，这样图例第二部分可以多行显示<br />
</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">{={sector}+1}.&lt;*advanceTo=22*&gt; 显示序号，并TAB到22px的位置（sector从0开始，所以要+1）<br />
</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">&lt;*block,width=120*&gt;{label}&lt;*/*&gt; 在120px长的block中显示标签，如果标签文字长于120px，则多行显示<br />
</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">&lt;*block,width=40,halign=right*&gt;{percent}&lt;*/*&gt;% 在40px长的block中显示百分比，并右对齐<br />
</span></span></p>
<p>&nbsp;</p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">代码：</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span"></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">21</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">24</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>, <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The colors to use for the sectors</span>
colors = <span style="color: black;">&#91;</span>0x66aaee, 0xeebb22, 0xbbbbbb, 0x8844ff, 0xdd2222, 0x009900<span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 600 x 320 pixels. Use a vertical gradient color</span>
<span style="color: #808080; font-style: italic;"># from light blue (99ccff) to white (ffffff) spanning the top 100 pixels as</span>
<span style="color: #808080; font-style: italic;"># background. Set border to grey (888888). Use rounded corners. Enable soft drop</span>
<span style="color: #808080; font-style: italic;"># shadow.</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">600</span>, <span style="color: #ff4500;">320</span><span style="color: black;">&#41;</span>
c.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>c.<span style="color: black;">linearGradientColor</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">100</span>, 0x99ccff, 0xffffff<span style="color: black;">&#41;</span>, 0x888888<span style="color: black;">&#41;</span>
c.<span style="color: black;">setRoundedFrame</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
c.<span style="color: black;">setDropShadow</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title using 18 pts Times New Roman Bold Italic font. Add 16 pixels top margin</span>
<span style="color: #808080; font-style: italic;"># to the title.</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Pie Chart With Legend Demonstration&quot;</span>, <span style="color: #483d8b;">&quot;timesbi.ttf&quot;</span>, <span style="color: #ff4500;">18</span><span style="color: black;">&#41;</span>.<span style="color: black;">setMargin2</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>,
    <span style="color: #ff4500;">16</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (160, 165) and the radius to 110 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">160</span>, <span style="color: #ff4500;">165</span>, <span style="color: #ff4500;">110</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D with a pie thickness of 25 pixels</span>
c.<span style="color: black;">set3D</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">25</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the sector colors</span>
c.<span style="color: black;">setColors2</span><span style="color: black;">&#40;</span>DataColor, colors<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use local gradient shading for the sectors</span>
c.<span style="color: black;">setSectorStyle</span><span style="color: black;">&#40;</span>LocalGradientShading<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use the side label layout method, with the labels positioned 16 pixels from the pie</span>
<span style="color: #808080; font-style: italic;"># bounding box</span>
c.<span style="color: black;">setLabelLayout</span><span style="color: black;">&#40;</span>SideLayout, <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Show only the sector number as the sector label</span>
c.<span style="color: black;">setLabelFormat</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;{={sector}+1}&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the sector label style to Arial Bold 10pt, with a dark grey (444444) border</span>
c.<span style="color: black;">setLabelStyle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;arialbd.ttf&quot;</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>Transparent, 0x444444<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a legend box, with the center of the left side anchored at (330, 175), and</span>
<span style="color: #808080; font-style: italic;"># using 10 pts Arial Bold Italic font</span>
b = c.<span style="color: black;">addLegend</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">330</span>, <span style="color: #ff4500;">175</span>, <span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;arialbi.ttf&quot;</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>
b.<span style="color: black;">setAlignment</span><span style="color: black;">&#40;</span>Left<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend box border to dark grey (444444), and with rounded conerns</span>
b.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>Transparent, 0x444444<span style="color: black;">&#41;</span>
b.<span style="color: black;">setRoundedCorners</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend box margin to 16 pixels, and the extra line spacing between the</span>
<span style="color: #808080; font-style: italic;"># legend entries as 5 pixels</span>
b.<span style="color: black;">setMargin</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
b.<span style="color: black;">setKeySpacing</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend box icon to have no border (border color same as fill color)</span>
b.<span style="color: black;">setKeyBorder</span><span style="color: black;">&#40;</span>SameAsMainColor<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend text to show the sector number, followed by a 120 pixels wide block</span>
<span style="color: #808080; font-style: italic;"># showing the sector label, and a 40 pixels wide block showing the percentage</span>
b.<span style="color: black;">setText</span><span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">&quot;&lt;*block,valign=top*&gt;{={sector}+1}.&lt;*advanceTo=22*&gt;&lt;*block,width=120*&gt;{label}&quot;</span> \
    <span style="color: #483d8b;">&quot;&lt;*/*&gt;&lt;*block,width=40,halign=right*&gt;{percent}&lt;*/*&gt;%&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;legendpie2.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/python/pychartdirector8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[7]：饼图的标签</title>
		<link>http://pwwang.com/technology/python/pychartdirector_7_chartlabel/</link>
		<comments>http://pwwang.com/technology/python/pychartdirector_7_chartlabel/#comments</comments>
		<pubDate>Thu, 13 May 2010 08:26:38 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=922</guid>
		<description><![CDATA[&#160;

下面我们看看如何用不同的方式来显示饼图的标签

1. 侧边标签层

<span class="readmore"><a href="http://pwwang.com/technology/python/pychartdirector_7_chartlabel/" title="PyChartDirector中文教程[7]：饼图的标签">Read More: 3627 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>下面我们看看如何用不同的方式来显示饼图的标签</p>
<p><strong>1. 侧边标签层</strong></p>
<p>先看看效果图:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/sidelabelpie.png"><img width="300" height="144" border="0" title="sidelabelpie" src="http://pwwang.com/wp-content/uploads/2010/05/sidelabelpie-300x144.png" style="clear: both;" alt="" /></a></p>
<p><span id="more-922"></span>标签的效果: 金属背景颜色, 圆角, 玻璃阴影效果</p>
<p>侧边标签层的标签将放置在图表的左侧和右侧</p>
<p>侧边标签层有一个好处, 那就是标签会自动上下排列, 防止交叠.</p>
<p>&nbsp;</p>
<p>金色的背景由 pychartdir.goldColor产生</p>
<p>粉色金属背景由pychartdir.metalColor产生, 用Box.setBackground来设置标题TextBox的背景颜色</p>
<p>侧边标签层由PieChart.setLabelLayout来指定</p>
<p>玻璃效果由pychartdir.glassEffect来增加, 用Box.setBackground来分别指定</p>
<p>圆角标签用Box.setRoundedCorners来设置</p>
<p>&nbsp;</p>
<p>如果数据中有些排序好的小值, 这个小值代表的块将会被放在一起, 这样标签就不需要太多的移动, 这个小值块更多的是在左边或者右边,而不是上边或者下边.</p>
<p>如果数据是降序排列的, 那么图的初始角度是顺时针135度,来保证那些小值块在45-135之间(在图的右边),&nbsp; 如果是升序, 则初始角度是45度.</p>
<p>代码:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">35</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">7</span>, <span style="color: #ff4500;">6</span>, <span style="color: #ff4500;">5</span>, <span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Production&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Misc&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>,
    <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Transport&quot;</span>, <span style="color: #483d8b;">&quot;Interest&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 560 x 270 pixels, with a golden background and a 1</span>
<span style="color: #808080; font-style: italic;"># pixel 3D border</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">560</span>, <span style="color: #ff4500;">270</span>, goldColor<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, -<span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title box using 15 pts Times Bold Italic font and metallic pink background</span>
<span style="color: #808080; font-style: italic;"># color</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Project Cost Breakdown&quot;</span>, <span style="color: #483d8b;">&quot;timesbi.ttf&quot;</span>, <span style="color: #ff4500;">15</span><span style="color: black;">&#41;</span>.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>metalColor<span style="color: black;">&#40;</span>
    0xff9999<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (280, 135) and the radius to 110 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">280</span>, <span style="color: #ff4500;">135</span>, <span style="color: #ff4500;">110</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D with 20 pixels 3D depth</span>
c.<span style="color: black;">set3D</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use the side label layout method</span>
c.<span style="color: black;">setLabelLayout</span><span style="color: black;">&#40;</span>SideLayout<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the label box background color the same as the sector color, with glass effect,</span>
<span style="color: #808080; font-style: italic;"># and with 5 pixels rounded corners</span>
t = c.<span style="color: black;">setLabelStyle</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
t.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>SameAsMainColor, Transparent, glassEffect<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
t.<span style="color: black;">setRoundedCorners</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the border color of the sector the same color as the fill color. Set the line</span>
<span style="color: #808080; font-style: italic;"># color of the join line to black (0x0)</span>
c.<span style="color: black;">setLineColor</span><span style="color: black;">&#40;</span>SameAsMainColor, 0x000000<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the start angle to 135 degrees may improve layout when there are many small</span>
<span style="color: #808080; font-style: italic;"># sectors at the end of the data array (that is, data sorted in descending order). It</span>
<span style="color: #808080; font-style: italic;"># is because this makes the small sectors position near the horizontal axis, where</span>
<span style="color: #808080; font-style: italic;"># the text label has the least tendency to overlap. For data sorted in ascending</span>
<span style="color: #808080; font-style: italic;"># order, a start angle of 45 degrees can be used instead.</span>
c.<span style="color: black;">setStartAngle</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">135</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sidelabelpie.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p><strong>2. 环形标签层</strong></p>
<p>看效果图:</p>
<p>&nbsp;<img width="300" height="300" border="0" title="circlelabelpie0" src="http://pwwang.com/wp-content/uploads/2010/05/circlelabelpie0-300x300.png" alt="" /> <a href="http://pwwang.com/wp-content/uploads/2010/05/circlelabelpie1.png"><img width="300" height="300" border="0" title="circlelabelpie1" src="http://pwwang.com/wp-content/uploads/2010/05/circlelabelpie1-300x300.png" style="clear: both;" alt="" /></a></p>
<p>&nbsp;这种环形标签有几种效果, 默认地是像最开始的例子那样,在图表的外面,紧挨着图.</p>
<p>Pie.setLabelPos可以用来控制标签与圆周之间的距离. 并可以在圆周和标签之间添加连接线, 当标签比较远的时候连接线是很有用的.</p>
<p>如果标签与圆周之间的距离是负值, 那么标签将会显示在圆周之内.</p>
<p>代码:</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> createChart<span style="color: black;">&#40;</span>img<span style="color: black;">&#41;</span> :
&nbsp;
    <span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
    data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">42</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">8</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
    labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Agree&quot;</span>, <span style="color: #483d8b;">&quot;Disagree&quot;</span>, <span style="color: #483d8b;">&quot;Not Sure&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># The colors to use for the sectors</span>
    colors = <span style="color: black;">&#91;</span>0x66ff66, 0xff6666, 0xffff00<span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Create a PieChart object of size 300 x 300 pixels. Set the background to a</span>
    <span style="color: #808080; font-style: italic;"># gradient color from blue (aaccff) to sky blue (ffffff), with a grey (888888)</span>
    <span style="color: #808080; font-style: italic;"># border. Use rounded corners and soft drop shadow.</span>
    c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">300</span>, <span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>
    c.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>c.<span style="color: black;">linearGradientColor</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, c.<span style="color: black;">getHeight</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">2</span>, 0xaaccff,
        0xffffff<span style="color: black;">&#41;</span>, 0x888888<span style="color: black;">&#41;</span>
    c.<span style="color: black;">setRoundedFrame</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    c.<span style="color: black;">setDropShadow</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> img == <span style="color: #483d8b;">&quot;0&quot;</span> :
    <span style="color: #808080; font-style: italic;">#============================================================</span>
    <span style="color: #808080; font-style: italic;">#    Draw a pie chart where the label is on top of the pie</span>
    <span style="color: #808080; font-style: italic;">#============================================================</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the center of the pie at (150, 150) and the radius to 120 pixels</span>
        c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">120</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the label position to -40 pixels from the perimeter of the pie (-ve</span>
        <span style="color: #808080; font-style: italic;"># means label is inside the pie)</span>
        c.<span style="color: black;">setLabelPos</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">40</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span> :
    <span style="color: #808080; font-style: italic;">#============================================================</span>
    <span style="color: #808080; font-style: italic;">#    Draw a pie chart where the label is outside the pie</span>
    <span style="color: #808080; font-style: italic;">#============================================================</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the center of the pie at (150, 150) and the radius to 80 pixels</span>
        c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">80</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the sector label position to be 20 pixels from the pie. Use a join line</span>
        <span style="color: #808080; font-style: italic;"># to connect the labels to the sectors.</span>
        c.<span style="color: black;">setLabelPos</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span>, LineColor<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
    c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Set the sector colors</span>
    c.<span style="color: black;">setColors2</span><span style="color: black;">&#40;</span>DataColor, colors<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Use local gradient shading, with a 1 pixel semi-transparent black (bb000000)</span>
    <span style="color: #808080; font-style: italic;"># border</span>
    c.<span style="color: black;">setSectorStyle</span><span style="color: black;">&#40;</span>LocalGradientShading, 0xbb000000L, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Output the chart</span>
    c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;circlelabelpie%s.png&quot;</span> <span style="color: #66cc66;">%</span> img<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
createChart<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;0&quot;</span><span style="color: black;">&#41;</span>
createChart<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;1&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/python/pychartdirector_7_chartlabel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[6]：多深度饼图</title>
		<link>http://pwwang.com/technology/python/pychartdirector_note_mdepthpie/</link>
		<comments>http://pwwang.com/technology/python/pychartdirector_note_mdepthpie/#comments</comments>
		<pubDate>Mon, 10 May 2010 01:22:55 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=914</guid>
		<description><![CDATA[&#160;

我们扩展了一下开始画的简单的饼图, 那还能不能再扩展一下呢, 

能否画出不同尝试的3D效果呢?

<span class="readmore"><a href="http://pwwang.com/technology/python/pychartdirector_note_mdepthpie/" title="PyChartDirector中文教程[6]：多深度饼图">Read More: 1009 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>我们扩展了一下开始画的简单的饼图, 那还能不能再扩展一下呢, </p>
<p>能否画出不同尝试的3D效果呢?</p>
<p>我们看看这个效果图:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/multidepthpie.png"><img width="300" height="250" border="0" title="multidepthpie" src="http://pwwang.com/wp-content/uploads/2010/05/multidepthpie-300x250.png" style="clear: both;" alt="" /></a></p>
<p><span id="more-914"></span></p>
<p>在这个例子中, 不再使用PieChart.set3D来画3D效果, 而是通过PieChart.set3D2来画图.</p>
<p>通过一个整数数组来指定不同区域的高度.</p>
<p>源代码如下:</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
31
32
33
34
35
36
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">72</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Machinery&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>, <span style="color: #483d8b;">&quot;Computers&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The depths for the sectors</span>
depths = <span style="color: black;">&#91;</span><span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">20</span>, <span style="color: #ff4500;">10</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 360 x 300 pixels, with a light blue (DDDDFF)</span>
<span style="color: #808080; font-style: italic;"># background and a 1 pixel 3D border</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">360</span>, <span style="color: #ff4500;">300</span>, 0xddddff, -<span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (180, 175) and the radius to 100 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">180</span>, <span style="color: #ff4500;">175</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title box using 15 pts Times Bold Italic font and blue (AAAAFF) as background</span>
<span style="color: #808080; font-style: italic;"># color</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Project Cost Breakdown&quot;</span>, <span style="color: #483d8b;">&quot;timesbi.ttf&quot;</span>, <span style="color: #ff4500;">15</span><span style="color: black;">&#41;</span>.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>0xaaaaff<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D with variable 3D depths, 指定不同区域的高度</span>
c.<span style="color: black;">set3D2</span><span style="color: black;">&#40;</span>depths<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the start angle to 225 degrees may improve layout when the depths of the sector</span>
<span style="color: #808080; font-style: italic;"># are sorted in descending order, because it ensures the tallest sector is at the</span>
<span style="color: #808080; font-style: italic;"># back.</span>
c.<span style="color: black;">setStartAngle</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">225</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;multidepthpie.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/python/pychartdirector_note_mdepthpie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[5]：3D饼图</title>
		<link>http://pwwang.com/technology/python/pychartdirector_note_3dpie/</link>
		<comments>http://pwwang.com/technology/python/pychartdirector_note_3dpie/#comments</comments>
		<pubDate>Fri, 07 May 2010 01:08:53 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=912</guid>
		<description><![CDATA[&#160;

前面我们画了一个非常简单的饼状图, 接下来,我们来扩展一下这个饼状图吧,

先看看我们扩展的这个3D饼图:

<span class="readmore"><a href="http://pwwang.com/technology/python/pychartdirector_note_3dpie/" title="PyChartDirector中文教程[5]：3D饼图">Read More: 710 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>前面我们画了一个非常简单的饼状图, 接下来,我们来扩展一下这个饼状图吧,</p>
<p>先看看我们扩展的这个3D饼图:</p>
<p>&nbsp;</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/threedpie.png"><img width="300" height="250" border="0" title="threedpie" src="http://pwwang.com/wp-content/uploads/2010/05/threedpie-300x250.png" style="clear: both;" alt="" /></a></p>
<p>&nbsp;</p>
<p><span id="more-912"></span>这个例子对先一个例子进行了扩展:</p>
<blockquote>
<p>用BaseChart.addTitle添加了标题</p>
<p>用PieChart.set3D画3D图</p>
<p>用PieChart.setExplode展开其中的一块区域</p>
</blockquote>
<p>源代码:</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">35</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>,
    <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 360 x 300 pixels</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">360</span>, <span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (180, 140) and the radius to 100 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">180</span>, <span style="color: #ff4500;">140</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title to the pie chart, 添加标题</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Project Cost Breakdown&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D, 3D模式</span>
c.<span style="color: black;">set3D</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Explode the 1st sector (index = 0)</span>
c.<span style="color: black;">setExplode</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;">#展开第一块区域</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;threedpie.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/python/pychartdirector_note_3dpie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[4]：简单的饼状图</title>
		<link>http://pwwang.com/default/pychartdirector_note_4/</link>
		<comments>http://pwwang.com/default/pychartdirector_note_4/#comments</comments>
		<pubDate>Tue, 04 May 2010 08:34:37 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[ChartDirector]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=907</guid>
		<description><![CDATA[&#160;

先来看看我们要画的这个最简单的饼状图吧:



<span class="readmore"><a href="http://pwwang.com/default/pychartdirector_note_4/" title="PyChartDirector中文教程[4]：简单的饼状图">Read More: 568 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>先来看看我们要画的这个最简单的饼状图吧:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/04/simplepie.png"><img width="300" height="250" border="0" alt="" style="clear: both;" src="http://pwwang.com/wp-content/uploads/2010/04/simplepie-300x250.png" title="simplepie" /></a></p>
<p>&nbsp;</p>
<p><span id="more-907"></span>这个例子展示了画饼状图的基本步骤:</p>
<blockquote>
<p>用PieChart创建一个pie chart对象</p>
<p>用setPieSize指定中心和半径</p>
<p>为饼状图指定数据</p>
<p>用makeChart保存图像</p>
</blockquote>
<p>我们先看一下源代码:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">35</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>,
    <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 360 x 300 pixels</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">360</span>, <span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (180, 140) and the radius to 100 pixels, </span>
<span style="color: #808080; font-style: italic;"># 圆心(180,140) 半径:100px</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">180</span>, <span style="color: #ff4500;">140</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels </span>
<span style="color: #808080; font-style: italic;"># 指定数据和标签</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;simplepie.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>简单吧!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/default/pychartdirector_note_4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[3]：嵌入网页</title>
		<link>http://pwwang.com/technology/python/pychartdirector_note_3/</link>
		<comments>http://pwwang.com/technology/python/pychartdirector_note_3/#comments</comments>
		<pubDate>Sat, 01 May 2010 08:12:14 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=901</guid>
		<description><![CDATA[&#160;

前面, 我们画了第一个图, 并把它保存到了文件, 下面我们看看怎么把它直接插入到网页中:



<span class="readmore"><a href="http://pwwang.com/technology/python/pychartdirector_note_3/" title="PyChartDirector中文教程[3]：嵌入网页">Read More: 973 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>前面, 我们画了第一个图, 并把它保存到了文件, 下面我们看看怎么把它直接插入到网页中:</p>
<p><span id="more-901"></span></p>
<p>文件: pythondemo_cgi\simplebar.py</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the bar chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">85</span>, <span style="color: #ff4500;">156</span>, <span style="color: #ff4500;">179.5</span>, <span style="color: #ff4500;">211</span>, <span style="color: #ff4500;">123</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the bar chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Mon&quot;</span>, <span style="color: #483d8b;">&quot;Tue&quot;</span>, <span style="color: #483d8b;">&quot;Wed&quot;</span>, <span style="color: #483d8b;">&quot;Thu&quot;</span>, <span style="color: #483d8b;">&quot;Fri&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a XYChart object of size 250 x 250 pixels</span>
c = XYChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">250</span>, <span style="color: #ff4500;">250</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the plotarea at (30, 20) and of size 200 x 200 pixels</span>
c.<span style="color: black;">setPlotArea</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">20</span>, <span style="color: #ff4500;">200</span>, <span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a bar chart layer using the given data</span>
c.<span style="color: black;">addBarLayer</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the labels on the x axis.</span>
c.<span style="color: black;">xAxis</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">setLabels</span><span style="color: black;">&#40;</span>labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Content-type: image/png<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
binaryPrint<span style="color: black;">&#40;</span>c.<span style="color: black;">makeChart2</span><span style="color: black;">&#40;</span>PNG<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>代码中, 前面部分和hello world的例子相同, 只有后面这两句有所不同:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Content-type: image/png<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
binaryPrint<span style="color: black;">&#40;</span>c.<span style="color: black;">makeChart2</span><span style="color: black;">&#40;</span>PNG<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>这两句是输出一个MIME类型的头部, 并输出一个准备送往浏览器的二进制图片.</p>
<p>上面的代码只是生成了一个二进制图片,那么我们如果把它插入到网页中呢?</p>
<p>其实和普通的图片的插入方法是一样的:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;HTML&gt;
&lt;BODY&gt;
&nbsp;
&lt;h1&gt;Hello World!&lt;/h1&gt;
&lt;p&gt;Hi, this is my first web page with ChartDirector charts.&lt;/p&gt;
&nbsp;
&lt;IMG SRC=&quot;http://aaa.bbb.ccc.ddd/cgi-bin/pythondemo_cgi/simplebar.py&quot;&gt;
&nbsp;
More HTML elements ......
&nbsp;
&lt;/BODY&gt;
&lt;/HTML&gt;</pre></td></tr></table></div>

<p>&nbsp;</p>
<p>&nbsp;在后面的例子中, 我们将不再例举CGI的例子, </p>
<p>因为只要将保存成图片的例子最后的makechart改成生成二进制图片的代码就行了</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/python/pychartdirector_note_3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[2]：Hello, world!</title>
		<link>http://pwwang.com/technology/python/pychartdirector_note_2/</link>
		<comments>http://pwwang.com/technology/python/pychartdirector_note_2/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 05:47:33 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=894</guid>
		<description><![CDATA[&#160;

&#160;前面我们已经了解了ChartDirector，也从我给出的图表中感受了它的强大，它所支持的图表类型已经基本上能满足我们的要求。

那么我们下面来看一下ChartDirector的Hello, world程序（当然不是打印一个Hello world，而是画一个简单的图表，如果你要那么认为，我只能表示无语凝噎。。。）

<span class="readmore"><a href="http://pwwang.com/technology/python/pychartdirector_note_2/" title="PyChartDirector中文教程[2]：Hello, world!">Read More: 1105 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>&nbsp;前面我们已经了解了ChartDirector，也从我给出的图表中感受了它的强大，它所支持的图表类型已经基本上能满足我们的要求。</p>
<p>那么我们下面来看一下ChartDirector的Hello, world程序（当然不是打印一个Hello world，而是画一个简单的图表，如果你要那么认为，我只能表示无语凝噎。。。）</p>
<p>我们要画的图就是我上一章给出的第一个图，一个简单的柱状图，我们再来看看它的美貌：</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/04/simplebar.png"><img title="simplebar" width="250" height="250" border="0" style="clear:both" alt="" src="http://pwwang.com/wp-content/uploads/2010/04/simplebar.png" /></a></p>
<p><span id="more-894"></span>让我们来看看这个图是怎么画的吧：</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the bar chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">85</span>, <span style="color: #ff4500;">156</span>, <span style="color: #ff4500;">179.5</span>, <span style="color: #ff4500;">211</span>, <span style="color: #ff4500;">123</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the bar chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Mon&quot;</span>, <span style="color: #483d8b;">&quot;Tue&quot;</span>, <span style="color: #483d8b;">&quot;Wed&quot;</span>, <span style="color: #483d8b;">&quot;Thu&quot;</span>, <span style="color: #483d8b;">&quot;Fri&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a XYChart object of size 250 x 250 pixels</span>
c = XYChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">250</span>, <span style="color: #ff4500;">250</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the plotarea at (30, 20) and of size 200 x 200 pixels</span>
c.<span style="color: black;">setPlotArea</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">20</span>, <span style="color: #ff4500;">200</span>, <span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a bar chart layer using the given data</span>
c.<span style="color: black;">addBarLayer</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the labels on the x axis.</span>
c.<span style="color: black;">xAxis</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">setLabels</span><span style="color: black;">&#40;</span>labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;simplebar.png&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>解释一下代码：</p>
<p>&nbsp;</p>
<blockquote>
<pre><strong>from pychartdir import *</strong></pre>
<div>导入pychardir模块</div>
<pre><strong>c = XYChart(250, 250)</strong></pre>
<p>ChartDirector中创建一个图表对象的第一步。在这个例子中，创建了一个250X250像素的XYChart对象。在ChartDirector中XYChart表示任何有x轴和y轴的图表，就像我们画的图一样。</p>
<pre><strong>c.setPlotArea(30, 30, 200, 200)</strong></pre>
<p>第二步是指定画图的位置和大小，四个参数分别是x坐标（left），y坐标（top），长度和宽度。这里要注意的是你的x+width不要超过了你设置的图表的总宽度，还要预留一些位置给文字标记。</p>
<pre><strong>c.addBarLayer(data)</strong></pre>
<p>上面的这个代码将柱状加到图表中。在ChartDirector中，所有的xy图表类型都用一个层来表现。一个XYChart可以包含多个层。</p>
<pre><strong>c.xAxis().setLabels(labels)</strong></pre>
<p>设置X轴的标签。</p>
<pre><strong>c.makeChart(&quot;simplebar.png&quot;)</strong></pre>
<p>保存到文件。<br />
支持的类型：PNG, JPG, GIF, BMP 和WBMP.</p>
</blockquote>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/python/pychartdirector_note_2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
