简体   繁体   English

为图表使用动态数据

[英]Employing dynamic data for graphs

I am aiming to build a site that will contain a lot of user generated data, hopefully. 我希望建立一个包含大量用户生成数据的站点。 I'm in my first year of self learning programming: Python, Django, MySQL, HTML and Javascript. 我正处于自学编程的第一年:Python,Django,MySQL,HTML和Javascript。

I can chart dummy data on a table just fine, but I'm now looking at turning that data into nice colorful looking graphs. 我可以很好地在桌面上绘制虚拟数据,但我现在正在考虑将这些数据转换成漂亮的彩色图形。

I am in my first day of investigation into finding out how to do this. 我正在调查第一天如何做到这一点。 But before I continue, I would like to ask a few questions. 但在我继续之前,我想问几个问题。

There seems to be many JavaScript frameworks for building charts, such as Google charts and jquery charts, and some object orientated programs for building charts, such as Cairo Plot and matplotlib. 似乎有许多用于构建图表的JavaScript框架,例如Google图表和jquery图表,以及一些用于构建图表的面向对象的程序,例如Cairo Plot和matplotlib。

The Javascript frameworks seem initially like a nice easy way to do it. Javascript框架似乎最初是一个很好的简单方法。 However, whereas with tables, where you can enter variable data tags in the body of an HTML page, and have Javascript make it look pretty, the data of a graph goes in the scripting area, where the variable data tags don't quite seem to work the same way. 但是,对于表格,您可以在HTML页面的正文中输入可变数据标记,并使Javascript使其看起来漂亮,图表的数据会进入脚本区域,其中可变数据标记看起来不太像以同样的方式工作。 I'm using Django, so a variable tag looks like: 我正在使用Django,因此变量标签看起来像:

{{ uniquenum }}   

Q1. Q1。 Should this work and am I just doing it wrong, or am I right in thinking variable tags can't go in the scripting area? 这应该工作,我只是做错了,还是我认为变量标签不能进入脚本区域?

Q2. Q2。 Can you have Javascript frameworks produce graphs from data outside the <script> area? 你能让Javascript框架从<script>区域外的数据生成图表吗?

Q3. Q3。 I've read that Javascript frameworks are getting more powerful, but because I'll be potentially using large amounts of dynamic data, should I be concentrating on using OO style graph programs like Cairo Plot and matplotlib, which to me don't seem to have the same levels of support? 我已经读过Javascript框架变得越来越强大,但是因为我可能会使用大量的动态数据,我是否应该专注于使用像Cairo Plot和matplotlib这样的OO样式图形程序,这对我来说似乎没有有相同的支持水平?

Just looking for a nudge in the right direction. 只是想朝着正确的方向努力。

How are the plots (typically) placed on the web page? 如何将图表(通常)放在网页上?

Here's the usual API schema for javascript-based data visualization libraries: 以下是基于javascript的数据可视化库的常用API架构:

i. 一世。 pre-allocate a div as the chart container in your markup (or template); 在标记(或模板)中预先分配div作为图表容器 ; typically using an id selector using an id selector, like so: 通常使用id选择器使用id选择器,如下所示:

<div id="chart1"> </div>

Often these libraries also require that this container be pre-sized--styled with height and width properties eg, 这些库通常也要求此容器预先调整大小 - 具有高度和宽度属性,例如,

<div id="chart1" style="height:300px;width:500px; "></div>

HTML5 libraries are particular about the container--ie, they require the chart to be placed inside the canvas tag, eg, HTML5库特别关于容器 - 即,它们要求将图表放在canvas标签内,例如,

ii. II。 call the plot constructor from your included javascript file and pass in (i) a data source; 从包含的javascript文件中调用plot构造函数并传入(i)数据源; (ii) aesthetic options (eg, axis labels), and (iii) the location in your markup of the container that will hold the plot; (ii)美学选择(例如轴标签),以及(iii)容纳标记的容器标记中的位置; this location is usually expected to be in the form of an id selector. 通常期望此位置采用id选择器的形式。 So in jqplot for instance inside the jQuery ready event, 所以在jqplot例如jQuery ready事件中,

plot1 = $.jqplot('chart1', [dataSet1, dataSet2], chartOptions)

javascript-based data visualization libraries i recommend (based on having used each for multiple projects). 我推荐的基于javascript的数据可视化库(基于已经将多个项目用于多个项目)。

I. conventional plotting formats: bar, line, point, pie I.常规绘图格式:条形,线条,点,饼图

Among javascript plotting libraries, i recommend the jQuery-based options because you need less code to create yoru plots and because it's easier to use jQuery's AJAX methods to load your data, for instance, jqplot , flot , and HighCharts (the three libraries that i recommend below) all include in their basic distribution, complete (html, css, js) example plots that demonstate loading data via AJAX. 在javascript绘图库中,我推荐基于jQuery的选项,因为你需要更少的代码来创建yoru图,并且因为使用jQuery的AJAX方法来加载你的数据更容易,例如, jqplotflotHighCharts (我的三个库)推荐如下)所有包括在他们的基本发行版中,完整的(html,css,js)示例图,通过AJAX演示加载数据。

  • HighCharts (open source but requires paid license for commercial use, but the most polished and longest feature list; active and fairly high signal-noise ratio forums on the HighCharts Site) HighCharts (开源但需要商业用途的付费许可,但是最精美和最长的功能列表; HighCharts网站上活跃且相当高的信噪比论坛)

  • flot (perhaps the most widely used) flot (也许是最广泛使用的)

  • jqplo t (large selection of plot types, highly modular, eg,. most functinality beyond the basics is added one plugin at a time) jqplo t (大量选择的绘图类型,高度模块化,例如,超出基础的大多数功能,一次添加一个插件)

II. II。 graphs, trees, network diagrams, etc. 图表,树木,网络图等

  • d3 (the successor to protovis; stunning graphic quality, rich interactive elements, animation; not strictly jQuery-based, but the author clearly borrowed the basic syntax patterns from jQuery; excellent tutorials on d3 by an accomplished data visualization specialist, Jan Willem Tulp Unlike the others mentioned here, this is a low-level library; indeed there are (at least) several plotting libraries based on d3, eg, rickshaw by shutterstock, and cube by Square. If you want conventional xy line/bar plots then for instance, you can build your plots in eg, HighCharts much faster. D3 becomes more interesting as use cases become more specific--in particular animation and unorthodox visualization (sunburst diagrams, chord diagrams, parallel line plots, geographic maps, etc.) d3 (protovis的继承者;令人惊叹的图形质量,丰富的交互元素,动画;不是严格基于jQuery的,但作者显然借用了jQuery的基本语法模式;由完美的数据可视化专家, Jan Willem Tulp不同于d3的优秀教程这里提到的其他人,这是一个低级库;确实有(至少)几个基于d3的绘图库,例如, shutterstock的人力车 ,以及Square的立方体 。如果你想要传统的xy线/条图,那么例如,你可以更快地在HighCharts中建立你的情节。随着用例变得更具体,D3变得更有趣 - 特别是动画非正统的可视化 (旭日图,和弦图,平行线图,地理地图等)

  • RafaelJS , renders in SVG, along with d3 and processing.js, you can make just about anything (eg, two-player games in the browser) with this library; RafaelJS ,在SVG中呈现,与d3和processing.js一起,你可以用这个库制作任何东西(例如,浏览器中的双人游戏); gRafael is a separate library for creating the usual plot types (bar, line, pie) gRafael是一个单独的库,用于创建通常的绘图类型(条形,直线,饼图)

III. III。 time-series plots 时间序列图

  • dygraphs (a javascript library dedidated soley to time-series plotting, and its feature set reflects this mission, eg, capacity to process and render plots with high volumes of data (>10,000 points), wide range of opdtions for tick labels of time axis with many formatting options dygraphs (一个javascript库将soley deley去了时间序列绘图,其功能集反映了这个任务,例如,处理和渲染具有大量数据(> 10,000点)的绘图的能力,时间轴刻度标签的广泛选项有许多格式选项

  • HighStock (a time-series library from the HighChart guys) HighStock (来自HighChart人的时间序列库)

IV. IV。 real-time/streaming data 实时/流数据

  • Smoothie Charts (sparse feature set, only intended to do one thing well which is smoothly render streaming data; HighCharts, jqplot, and flot will also do this, but depending on the character of your data (variance, rate) these three general-purpose libraries might not show the data as "spiky", which is precisely what Smoothie was designed to eliminate) Smoothie Charts (稀疏功能集,仅用于做一件事,它可以顺利渲染流数据; HighCharts,jqplot和flot也会这样做,但取决于你的数据的特性(方差,速率)这三个通用图书馆可能不会将数据显示为“尖尖”,这正是Smoothie旨在消除的数据)

If you're going to deal with very large datasets (>10000 elements), you will probably run into performance problems, no matter what Javascript library you end up picking. 如果您要处理非常大的数据集(> 10000个元素),无论您最终选择哪个Javascript库,都可能会遇到性能问题。

Having said that, there's a growing number of Javascript toolkits which dynamycally load the data set with an HTTP request as a JSON, XML, etc... flot is pretty fast and open source. 话虽如此,有越来越多的Javascript工具包使用HTTP请求动态加载数据集作为JSON,XML等... flot是非常快速和开源的。 Highcharts is very feature rich and free for non-commercial projects. Highcharts功能丰富,非商业项目免费。 And if you need more esoteric visualizations, you must take a look at d3.js . 如果你需要更多深奥的可视化,你必须看看d3.js。

I have found another javascript charting library to be useful for streaming data = https://github.com/INRIA/VisualSedimentation . 我发现另一个javascript图表库对流数据有用= https://github.com/INRIA/VisualSedimentation The code is baed on d3.js, but has some good extensibility. 该代码基于d3.js,但具有一些良好的可扩展性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM