SlideShare a Scribd company logo
django로 차트 그리기
requirements :
• python
• django package
• jquery
프로젝트 디렉토리 생성
프로젝트 디렉토리 확인
hwangyoungjae
├hwangyoungjae
│├__init__.py
│├settings.py
│├urls.py
│└wsgi.py
└manage.py
db파일 생성 및 관리자 계정 생성
app 생성
settings.py에 app 추가
INSTALLED_APPS = [
'firstapp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
hwangyoungjaehwangyoungjaesettings.py
개발모드로 실행하기
접속
view, url 추가
hwangyoungjaefirstappviews.py
from django.shortcuts import render, HttpResponse
# Create your views here.
def test_page(request):
return HttpResponse('Hello, Python')
hwangyoungjaehwangyoungjaeurls.py
from django.conf.urls import url
from django.contrib import admin
import firstapp.views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^test$',firstapp.views.test_page)
]
테스트 페이지 접속
챠트 데이터용 view 추가
def chart_data(request):
DataFrame = pandas_datareader.data.DataReader(
'000500.KS',
"yahoo",
datetime.date.today() - datetime.timedelta(days=365),
datetime.date.today())
datas = []
for index in DataFrame['Open'].index:
data = [
int(time.mktime(time.strptime(str(index), '%Y-%m-%d %H:%M:%S')) * 1000),
DataFrame['Open'][index],
DataFrame['High'][index],
DataFrame['Low'][index],
DataFrame['Close'][index],
]
datas.append(data)
return HttpResponse(json.dumps(datas),content_type='text/json')
hwangyoungjaefirstappviews.py
hwangyoungjaehwangyoungjaeurls.py
url(r'^chart.data$', firstapp.views.chart_data),
데이터 확인하기
챠트 그리기용 템플릿 디렉토리 생성 및 파일 추가
hwangyoungjaefirstapptemplateschart.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="height: 400px; min-width: 310px"></div>
<script type="text/javascript">
$(function () {
$.getJSON('/chart.data', function (data) {
Highcharts.stockChart('container', {
title: {
text: '{{ name }}',
},
series: [{
type: 'candlestick',
data: data,
}]
});
});
});
</script>
</body>
</html>
챠트 그리기용 view, url 추가
def chart_page(request):
name = '가온전선'
return render(request, 'chart.html',{'name':name,})
hwangyoungjaefirstappviews.py
hwangyoungjaehwangyoungjaeurls.py
url(r'^chart$', firstapp.views.chart_page),
확인하기
끝내는말
본 문서는 django를 깊게 파지도 않았고,
highchart를 깊게 파지도 않았다.
django로 챠트를 그릴수 있다는 정도만 될것이다.
해본 사람이라면 알겠지만,
highchart는 사실 django와 전혀 관련이 없다.
javascript로 구현되기 때문에다
django를 이용하는건 data를 만드는걸 보여주기 위함이다.
dudwo56@gmail.com

More Related Content

Viewers also liked

Night Bird the Brian Freeman
Night Bird the Brian FreemanNight Bird the Brian Freeman
Night Bird the Brian Freeman
Lirigzon Gashi
 
C interview Question and Answer
C interview Question and AnswerC interview Question and Answer
C interview Question and Answer
Jagan Mohan Bishoyi
 
1. structure-of-the-earth (1)
1. structure-of-the-earth (1)1. structure-of-the-earth (1)
1. structure-of-the-earth (1)
Tacius Golding High
 
Quiz em libras 2017
Quiz em libras 2017Quiz em libras 2017
Quiz em libras 2017
Nelinha Soares
 
London Adapt or Die: Closing Keynote — Adapt Now!
London Adapt or Die: Closing Keynote — Adapt Now!London Adapt or Die: Closing Keynote — Adapt Now!
London Adapt or Die: Closing Keynote — Adapt Now!
Apigee | Google Cloud
 
Microservices Done Right: Key Ingredients for Microservices Success
Microservices Done Right: Key Ingredients for Microservices SuccessMicroservices Done Right: Key Ingredients for Microservices Success
Microservices Done Right: Key Ingredients for Microservices Success
Apigee | Google Cloud
 

Viewers also liked (6)

Night Bird the Brian Freeman
Night Bird the Brian FreemanNight Bird the Brian Freeman
Night Bird the Brian Freeman
 
C interview Question and Answer
C interview Question and AnswerC interview Question and Answer
C interview Question and Answer
 
1. structure-of-the-earth (1)
1. structure-of-the-earth (1)1. structure-of-the-earth (1)
1. structure-of-the-earth (1)
 
Quiz em libras 2017
Quiz em libras 2017Quiz em libras 2017
Quiz em libras 2017
 
London Adapt or Die: Closing Keynote — Adapt Now!
London Adapt or Die: Closing Keynote — Adapt Now!London Adapt or Die: Closing Keynote — Adapt Now!
London Adapt or Die: Closing Keynote — Adapt Now!
 
Microservices Done Right: Key Ingredients for Microservices Success
Microservices Done Right: Key Ingredients for Microservices SuccessMicroservices Done Right: Key Ingredients for Microservices Success
Microservices Done Right: Key Ingredients for Microservices Success
 

Similar to Django+highchart

Python codelab1
Python codelab1Python codelab1
Python codelab1
건희 김
 
쉽게 쓰여진 Django
쉽게 쓰여진 Django쉽게 쓰여진 Django
쉽게 쓰여진 Django
Taehoon Kim
 
Django
DjangoDjango
Light Tutorial Django
Light Tutorial DjangoLight Tutorial Django
Light Tutorial Django
Kwangyoun Jung
 
2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축
2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축
2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축
Youngil Cho
 
장고로 웹서비스 만들기 기초
장고로 웹서비스 만들기   기초장고로 웹서비스 만들기   기초
장고로 웹서비스 만들기 기초
Kwangyoun Jung
 
Python codelab2
Python codelab2Python codelab2
Python codelab2
건희 김
 
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Dongil Yeom
 
Docker (Compose) 활용 - 개발 환경 구성하기
Docker (Compose) 활용 - 개발 환경 구성하기Docker (Compose) 활용 - 개발 환경 구성하기
Docker (Compose) 활용 - 개발 환경 구성하기
raccoony
 
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
I Goo Lee
 
REST API Development with Spring
REST API Development with SpringREST API Development with Spring
REST API Development with Spring
Keesun Baik
 
구글앱엔진 스터디
구글앱엔진 스터디구글앱엔진 스터디
구글앱엔진 스터디
소라 정
 
Grunt
GruntGrunt
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
Youngbin Han
 
Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기
Kyoung Up Jung
 
R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁
R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁
R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁
창규 김
 
프로덕트 매니저 8년의 경험
프로덕트 매니저 8년의 경험프로덕트 매니저 8년의 경험
프로덕트 매니저 8년의 경험
Jihye OK
 
[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp
NAVER D2
 
Hacosa js study 4주차
Hacosa js study 4주차Hacosa js study 4주차
Hacosa js study 4주차Seong Bong Ji
 
Django로 배우는 쉽고 빠른 웹개발 study 자료
Django로 배우는 쉽고 빠른 웹개발 study 자료Django로 배우는 쉽고 빠른 웹개발 study 자료
Django로 배우는 쉽고 빠른 웹개발 study 자료
Han Sung Kim
 

Similar to Django+highchart (20)

Python codelab1
Python codelab1Python codelab1
Python codelab1
 
쉽게 쓰여진 Django
쉽게 쓰여진 Django쉽게 쓰여진 Django
쉽게 쓰여진 Django
 
Django
DjangoDjango
Django
 
Light Tutorial Django
Light Tutorial DjangoLight Tutorial Django
Light Tutorial Django
 
2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축
2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축
2017 Pycon KR - Django/AWS 를 이용한 쇼핑몰 서비스 구축
 
장고로 웹서비스 만들기 기초
장고로 웹서비스 만들기   기초장고로 웹서비스 만들기   기초
장고로 웹서비스 만들기 기초
 
Python codelab2
Python codelab2Python codelab2
Python codelab2
 
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
 
Docker (Compose) 활용 - 개발 환경 구성하기
Docker (Compose) 활용 - 개발 환경 구성하기Docker (Compose) 활용 - 개발 환경 구성하기
Docker (Compose) 활용 - 개발 환경 구성하기
 
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
 
REST API Development with Spring
REST API Development with SpringREST API Development with Spring
REST API Development with Spring
 
구글앱엔진 스터디
구글앱엔진 스터디구글앱엔진 스터디
구글앱엔진 스터디
 
Grunt
GruntGrunt
Grunt
 
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
 
Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기
 
R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁
R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁
R.java가 사라졌어요 어떻하죠?:Aquery라이브러리와 안드로이드 개발팁
 
프로덕트 매니저 8년의 경험
프로덕트 매니저 8년의 경험프로덕트 매니저 8년의 경험
프로덕트 매니저 8년의 경험
 
[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp[D2 오픈세미나]3.web view hybridapp
[D2 오픈세미나]3.web view hybridapp
 
Hacosa js study 4주차
Hacosa js study 4주차Hacosa js study 4주차
Hacosa js study 4주차
 
Django로 배우는 쉽고 빠른 웹개발 study 자료
Django로 배우는 쉽고 빠른 웹개발 study 자료Django로 배우는 쉽고 빠른 웹개발 study 자료
Django로 배우는 쉽고 빠른 웹개발 study 자료
 

Django+highchart

  • 2. requirements : • python • django package • jquery
  • 5. db파일 생성 및 관리자 계정 생성
  • 7. settings.py에 app 추가 INSTALLED_APPS = [ 'firstapp', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] hwangyoungjaehwangyoungjaesettings.py
  • 10. view, url 추가 hwangyoungjaefirstappviews.py from django.shortcuts import render, HttpResponse # Create your views here. def test_page(request): return HttpResponse('Hello, Python') hwangyoungjaehwangyoungjaeurls.py from django.conf.urls import url from django.contrib import admin import firstapp.views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^test$',firstapp.views.test_page) ]
  • 12. 챠트 데이터용 view 추가 def chart_data(request): DataFrame = pandas_datareader.data.DataReader( '000500.KS', "yahoo", datetime.date.today() - datetime.timedelta(days=365), datetime.date.today()) datas = [] for index in DataFrame['Open'].index: data = [ int(time.mktime(time.strptime(str(index), '%Y-%m-%d %H:%M:%S')) * 1000), DataFrame['Open'][index], DataFrame['High'][index], DataFrame['Low'][index], DataFrame['Close'][index], ] datas.append(data) return HttpResponse(json.dumps(datas),content_type='text/json') hwangyoungjaefirstappviews.py hwangyoungjaehwangyoungjaeurls.py url(r'^chart.data$', firstapp.views.chart_data),
  • 14. 챠트 그리기용 템플릿 디렉토리 생성 및 파일 추가 hwangyoungjaefirstapptemplateschart.html <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="https://code.highcharts.com/stock/highstock.js"></script> <script src="https://code.highcharts.com/stock/modules/exporting.js"></script> </head> <body> <div id="container" style="height: 400px; min-width: 310px"></div> <script type="text/javascript"> $(function () { $.getJSON('/chart.data', function (data) { Highcharts.stockChart('container', { title: { text: '{{ name }}', }, series: [{ type: 'candlestick', data: data, }] }); }); }); </script> </body> </html>
  • 15. 챠트 그리기용 view, url 추가 def chart_page(request): name = '가온전선' return render(request, 'chart.html',{'name':name,}) hwangyoungjaefirstappviews.py hwangyoungjaehwangyoungjaeurls.py url(r'^chart$', firstapp.views.chart_page),
  • 17. 끝내는말 본 문서는 django를 깊게 파지도 않았고, highchart를 깊게 파지도 않았다. django로 챠트를 그릴수 있다는 정도만 될것이다. 해본 사람이라면 알겠지만, highchart는 사실 django와 전혀 관련이 없다. javascript로 구현되기 때문에다 django를 이용하는건 data를 만드는걸 보여주기 위함이다. dudwo56@gmail.com