Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript django海图_Javascript_Django_Highcharts_Django Templates - Fatal编程技术网

Javascript django海图

Javascript django海图,javascript,django,highcharts,django-templates,Javascript,Django,Highcharts,Django Templates,我是django的新手。我想用django中的highcharts来绘制图表。我所做的是创建了一个名为Telecom的项目。然后我把highcharts文件放在Telecom/media/highcharts文件夹中。我在Telecom/media/js位置写了一个script.js文件 script.js $(function () { $('#container').highcharts({ chart: { type:

我是django的新手。我想用django中的highcharts来绘制图表。我所做的是创建了一个名为Telecom的项目。然后我把highcharts文件放在Telecom/media/highcharts文件夹中。我在Telecom/media/js位置写了一个script.js文件

script.js

$(function () {
        $('#container').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'Monthly Average Rainfall'
            },
            subtitle: {
                text: 'Source: WorldClimate.com'
            },
            xAxis: {
                categories: [
                    'Jan',
                    'Feb',
                    'Mar',
                    'Apr',
                    'May',
                    'Jun',
                    'Jul',
                    'Aug',
                    'Sep',
                    'Oct',
                    'Nov',
                    'Dec'
                ]
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Rainfall (mm)'
                }
            },
            tooltip: {
                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                    '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
                footerFormat: '</table>',
                shared: true,
                useHTML: true
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            series: [{
                name: 'Tokyo',
                data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

            }, {
                name: 'New York',
                data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]

            }, {
                name: 'London',
                data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]

            }, {
                name: 'Berlin',
                data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]

            }]
        });
    });
DEBUG = True
TEMPLATE_DEBUG = DEBUG

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

PROJECT_DIR = os.path.dirname(__file__)

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)


MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'telecom_db',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '127.0.0.1',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
    }
}

ALLOWED_HOSTS = []

TIME_ZONE = 'America/Chicago'

LANGUAGE_CODE = 'UTC'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

MEDIA_ROOT = os.path.join(PROJECT_DIR,'..', 'media')

MEDIA_URL = 'http://localhost:8000/media/'

STATIC_ROOT = ''

STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = '/media/admin/'

# Additional locations of static files
STATICFILES_DIRS = (

)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'b9_hyqe*b&ra_&wlm5a9xas_ag#5mjv-dy=to%hdk_u-#xvn*l'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#    'django.template.loaders.eggs.Loader',
)

TEMPLATE_DIRS = (       
                  os.path.join(PROJECT_DIR, '..','templates'),
#                  os.path.join(PROJECT_DIR, 'templates/welcome'),
)


MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'Telecom.urls'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.admin',

    'django.contrib.admindocs',
    'welcome',
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

但是图形没有显示,如何使其工作?

您的程序需要internet来显示图形,因为.js文件位置来自url。若你们想离线加载图形,那个么下载所需的库(js文件)并进行如下更改

settings.py#更新静态根目录和url

STATIC_ROOT = ''
STATIC_URL = '/static/'
现在将您的.js(源文件)放入在应用程序文件夹中创建的静态文件夹中

现在在模板加载
.js
文件中,将下面的代码放在标题标记中

{% load staticfiles %}    
    <script src="{% static "js/jquery-1.3.2.min.js" %}"></script>
    <script src="{% static "js/script.js" %}"></script>
{%load staticfiles%}

在这里,我将示例js库放置在目录位置中,如
/my_app/static/js/…
,所以在src上,您需要在静态文件夹之后给出位置。希望您在回答此问题后能够显示图表。

希望这将有助于您:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

SETTINGS_FILE_PATH = os.path.realpath(__file__)

SETTINGS_DIR = os.path.dirname(SETTINGS_FILE_PATH)

PROJECT_DIR = os.path.dirname(SETTINGS_DIR)

MEDIA_DIR = os.path.join(PROJECT_DIR, 'media')

STATIC_DIR = os.path.join(PROJECT_DIR, 'static')

STATIC_URL = '/static/'


STATICFILES_DIRS = (
    STATIC_DIR,
)

MEDIA_URL = '/media/'
MEDIA_ROOT = MEDIA_DIR


TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, 'templates'),
    )

可能重复的和许多其他的,所以我已经尝试了这些链接,但找不到解决办法,请在我的上下文中帮助。
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

SETTINGS_FILE_PATH = os.path.realpath(__file__)

SETTINGS_DIR = os.path.dirname(SETTINGS_FILE_PATH)

PROJECT_DIR = os.path.dirname(SETTINGS_DIR)

MEDIA_DIR = os.path.join(PROJECT_DIR, 'media')

STATIC_DIR = os.path.join(PROJECT_DIR, 'static')

STATIC_URL = '/static/'


STATICFILES_DIRS = (
    STATIC_DIR,
)

MEDIA_URL = '/media/'
MEDIA_ROOT = MEDIA_DIR


TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, 'templates'),
    )