데브피아 신인식님의 글입니다.
--------------------------------------------------------------
아래는 MicroSoft Office Web Component를 이용하여
챠트를 생성하는 방법입니다.
챠트가 gif 로 생성이 됩니다.
물론 서버에 오피스가 설치되어 있거나 OWC 가 설치되어있어야 합니다.
아래는 막대그래프와 선형그래프만을 예로 들었습니다.
잘 응용하시면 파이형, 도너츠형~ 모두 가능합니다.
테이블은 하나 만드시구여...
저는 test라는 테이블일 만들고
group int,test varchar ,score int 이렇게 컬럼을 만들었습니다.
그리고 값들을
group test score
------------------
1 a 3
1 b 1
1 c 2
2 a 2
2 b 5
2 c 1
3 a 2
3 b 3
3 c 4
이렇게 넣었습니다.
사용된 코드는 좀 허접이지만...
일단 사용법만 봐주세여... ㅋㅋ
<%@ Language=VBScript %>
<%
set m_cn = Server.CreateObject("ADODB.Connection")
set m_rs = Server.CreateObject("ADODB.Recordset")
m_cn.Open
("Provider=SQLOLEDB;SERVER=211.240.58.51;Uid=sa;Pwd=8080;Database=iuri
m;network library=dbmssocn")
sSQL = "select test, score, [group] from testscore"
m_rs.CursorLocation = 3
m_rs.Open sSQL, m_cn, 3
%>
<html>
<style>
td {font-size:9pt}
</style>
<body>
<table border=1 width=200 cellspacing=0>
<tr>
<td colspan=3 align=center><b>입력값</b></td>
</tr>
<tr>
<td align=center>group</td>
<td align=center>test</td>
<td align=center>score</td>
</tr>
<%
do until m_rs.EOF
%>
<tr>
<td align=center><%= m_rs(2)%></td>
<td align=center><%= m_rs(0)%></td>
<td align=center><%= m_rs(1)%></td>
</tr>
<%
m_rs.MoveNext
Loop
%>
</table>
<%
set m_cspace = server.CreateObject("OWC.Chart")
set cht = m_cspace.Charts.Add()
set c = m_cspace.Constants
cht.Type = c.chChartTypeColumnClustered ''막대그래프
cht.HasLegend = True
set m_cspace.DataSource = m_rs
cht.SetData c.chDimSeriesNames, 0, "test" ''가로축
cht.SetData c.chDimCategories, 0, "[group]" ''그룹
cht.SetData c.chDimValues, 0, "score" ''세로축
''챠트 타이틀
cht.HasTitle = True
cht.Title.Caption = "Test Score"
set fnt = cht.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 10
fnt.Bold = True
''가로축 설정
set ax = cht.Axes(c.chAxisPositionBottom)
ax.HasTitle = True
ax.Title.Caption = "test"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
''세로축 설정
set ax = cht.Axes(c.chAxisPositionLeft)
''ax.NumberFormat = "Currency"
ax.HasTitle = True
ax.Title.Caption = "score"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
sFullFileName = Server.MapPath(".") & "\" & "test.gif"
''owc에서 생성된 그래프를 이미지 화일로 Export 시킵니다.
m_cspace.ExportPicture sFullFileName, "gif", 600, 200
Response.Write "<img src=test.gif>"
set m_cspace = server.CreateObject("OWC.Chart")
set cht = m_cspace.Charts.Add()
set c = m_cspace.Constants
cht.Type = c.chChartTypeLine ''선형그래프
cht.HasLegend = True
set m_cspace.DataSource = m_rs
cht.SetData c.chDimSeriesNames, 0, "test" ''가로축
cht.SetData c.chDimCategories, 0, "[group]" ''그룹
cht.SetData c.chDimValues, 0, "score" ''세로축
''챠트 타이틀
cht.HasTitle = True
cht.Title.Caption = "Test Score"
set fnt = cht.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 10
fnt.Bold = True
''가로축 설정
set ax = cht.Axes(c.chAxisPositionBottom)
ax.HasTitle = True
ax.Title.Caption = "test"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
''세로축 설정
set ax = cht.Axes(c.chAxisPositionLeft)
''ax.NumberFormat = "Currency"
ax.HasTitle = True
ax.Title.Caption = "score"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
sFullFileName = Server.MapPath(".") & "\" & "test2.gif"
m_cspace.ExportPicture sFullFileName, "gif", 600, 200
Response.Write "<img src=test2.gif>"
%>
</body>
</html>
--------------------------------------------------------------
아래는 MicroSoft Office Web Component를 이용하여
챠트를 생성하는 방법입니다.
챠트가 gif 로 생성이 됩니다.
물론 서버에 오피스가 설치되어 있거나 OWC 가 설치되어있어야 합니다.
아래는 막대그래프와 선형그래프만을 예로 들었습니다.
잘 응용하시면 파이형, 도너츠형~ 모두 가능합니다.
테이블은 하나 만드시구여...
저는 test라는 테이블일 만들고
group int,test varchar ,score int 이렇게 컬럼을 만들었습니다.
그리고 값들을
group test score
------------------
1 a 3
1 b 1
1 c 2
2 a 2
2 b 5
2 c 1
3 a 2
3 b 3
3 c 4
이렇게 넣었습니다.
사용된 코드는 좀 허접이지만...
일단 사용법만 봐주세여... ㅋㅋ
<%@ Language=VBScript %>
<%
set m_cn = Server.CreateObject("ADODB.Connection")
set m_rs = Server.CreateObject("ADODB.Recordset")
m_cn.Open
("Provider=SQLOLEDB;SERVER=211.240.58.51;Uid=sa;Pwd=8080;Database=iuri
m;network library=dbmssocn")
sSQL = "select test, score, [group] from testscore"
m_rs.CursorLocation = 3
m_rs.Open sSQL, m_cn, 3
%>
<html>
<style>
td {font-size:9pt}
</style>
<body>
<table border=1 width=200 cellspacing=0>
<tr>
<td colspan=3 align=center><b>입력값</b></td>
</tr>
<tr>
<td align=center>group</td>
<td align=center>test</td>
<td align=center>score</td>
</tr>
<%
do until m_rs.EOF
%>
<tr>
<td align=center><%= m_rs(2)%></td>
<td align=center><%= m_rs(0)%></td>
<td align=center><%= m_rs(1)%></td>
</tr>
<%
m_rs.MoveNext
Loop
%>
</table>
<%
set m_cspace = server.CreateObject("OWC.Chart")
set cht = m_cspace.Charts.Add()
set c = m_cspace.Constants
cht.Type = c.chChartTypeColumnClustered ''막대그래프
cht.HasLegend = True
set m_cspace.DataSource = m_rs
cht.SetData c.chDimSeriesNames, 0, "test" ''가로축
cht.SetData c.chDimCategories, 0, "[group]" ''그룹
cht.SetData c.chDimValues, 0, "score" ''세로축
''챠트 타이틀
cht.HasTitle = True
cht.Title.Caption = "Test Score"
set fnt = cht.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 10
fnt.Bold = True
''가로축 설정
set ax = cht.Axes(c.chAxisPositionBottom)
ax.HasTitle = True
ax.Title.Caption = "test"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
''세로축 설정
set ax = cht.Axes(c.chAxisPositionLeft)
''ax.NumberFormat = "Currency"
ax.HasTitle = True
ax.Title.Caption = "score"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
sFullFileName = Server.MapPath(".") & "\" & "test.gif"
''owc에서 생성된 그래프를 이미지 화일로 Export 시킵니다.
m_cspace.ExportPicture sFullFileName, "gif", 600, 200
Response.Write "<img src=test.gif>"
set m_cspace = server.CreateObject("OWC.Chart")
set cht = m_cspace.Charts.Add()
set c = m_cspace.Constants
cht.Type = c.chChartTypeLine ''선형그래프
cht.HasLegend = True
set m_cspace.DataSource = m_rs
cht.SetData c.chDimSeriesNames, 0, "test" ''가로축
cht.SetData c.chDimCategories, 0, "[group]" ''그룹
cht.SetData c.chDimValues, 0, "score" ''세로축
''챠트 타이틀
cht.HasTitle = True
cht.Title.Caption = "Test Score"
set fnt = cht.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 10
fnt.Bold = True
''가로축 설정
set ax = cht.Axes(c.chAxisPositionBottom)
ax.HasTitle = True
ax.Title.Caption = "test"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
''세로축 설정
set ax = cht.Axes(c.chAxisPositionLeft)
''ax.NumberFormat = "Currency"
ax.HasTitle = True
ax.Title.Caption = "score"
set fnt = ax.Title.Font
fnt.Name = "Tahoma"
fnt.Size = 8
fnt.Bold = True
sFullFileName = Server.MapPath(".") & "\" & "test2.gif"
m_cspace.ExportPicture sFullFileName, "gif", 600, 200
Response.Write "<img src=test2.gif>"
%>
</body>
</html>