te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Employing dynamic data for graphs - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Employing dynamic data for graphs - Stack Overflow

programmeradmin3浏览0评论

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.

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.

The Javascript frameworks seem initially like a nice easy way to do it. 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. I'm using Django, so a variable tag looks like:

{{ uniquenum }}   

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. Can you have Javascript frameworks produce graphs from data outside the <script> area?

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?

Just looking for a nudge in the right direction.

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.

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.

The Javascript frameworks seem initially like a nice easy way to do it. 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. I'm using Django, so a variable tag looks like:

{{ uniquenum }}   

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. Can you have Javascript frameworks produce graphs from data outside the <script> area?

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?

Just looking for a nudge in the right direction.

Share Improve this question edited Dec 20, 2011 at 13:53 Chewie 7,2355 gold badges31 silver badges36 bronze badges asked Dec 20, 2011 at 12:55 JT.JT. 3511 gold badge5 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 15

How are the plots (typically) placed on the web page?

Here's the usual API schema for javascript-based data visualization libraries:

i. pre-allocate a div as the chart container in your markup (or template); typically using an id selector using an id selector, like so:

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

Often these libraries also require that this container be pre-sized--styled with height and width properties e.g.,

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

HTML5 libraries are particular about the container--i.e., they require the chart to be placed inside the canvas tag, e.g.,

ii. call the plot constructor from your included javascript file and pass in (i) a data source; (ii) aesthetic options (e.g., axis labels), and (iii) the location in your markup of the container that will hold the plot; this location is usually expected to be in the form of an id selector. So in jqplot for instance inside the jQuery ready event,

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

javascript-based data visualization libraries i remend (based on having used each for multiple projects).

I. conventional plotting formats: bar, line, point, pie

Among javascript plotting libraries, i remend 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 remend below) all include in their basic distribution, plete (html, css, js) example plots that demonstate loading data via AJAX.

  • HighCharts (open source but requires paid license for mercial use, but the most polished and longest feature list; active and fairly high signal-noise ratio forums on the HighCharts Site)

  • flot (perhaps the most widely used)

  • jqplot (large selection of plot types, highly modular, e.g,. most functinality beyond the basics is added one plugin at a time)

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 acplished 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, e.g., rickshaw by shutterstock, and cube by Square. If you want conventional x-y line/bar plots then for instance, you can build your plots in e.g., HighCharts much faster. D3 bees more interesting as use cases bee more specific--in particular animation and unorthodox visualization (sunburst diagrams, chord diagrams, parallel line plots, geographic maps, etc.)

  • RafaelJS, renders in SVG, along with d3 and processing.js, you can make just about anything (e.g., two-player games in the browser) with this library; gRafael is a separate library for creating the usual plot types (bar, line, pie)

III. time-series plots

  • dygraphs (a javascript library dedidated soley to time-series plotting, and its feature set reflects this mission, e.g., 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

  • HighStock (a time-series library from the HighChart guys)

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)

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.

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. Highcharts is very feature rich and free for non-mercial projects. And if you need more esoteric visualizations, you must take a look at d3.js.

I have found another javascript charting library to be useful for streaming data = https://github./INRIA/VisualSedimentation. The code is baed on d3.js, but has some good extensibility.

发布评论

评论列表(0)

  1. 暂无评论