Flot Reference
flot参考文档十六进制数在书写时常在后面加什么字母
--------------
Consider a call to the plot function:
下面是对绘图函数plot的调用:
var plot = $.plot(placeholder, data, options)
The placeholder is a jQuery object or DOM element or jQuery expression
that the plot will be put into. This placeholder needs to have its
jquery下载文件请求
width and height set as explained in the README (go read that now if
you haven't, it's short). The plot will modify some properties of the
placeholder so it's recommended you simply pass in a div that you
don't use for anything else. Make sure you check any fancy styling
you apply to the div, e.g. background images have been reported to be a
problem on IE 7.
占位符placeholder是一个jQuery对象或者DOM元素或者jQuery表单式,绘图函数将把图表画在placeholder内。
这个占位符需要设置高宽(这在README文档里面已经介绍过,如果你还没有阅读过现在就去阅读吧,文档很短)。
plot函数画图时将修改这个占位符的内容,因此你最好使用一个空的DIV元素作为占位符,另外注意不要给占位符
设置花哨的样式,比如,在IE7.0下,给占位符设置背景图将会出错。
The format of the data is documented below, as is the available
options. The "plot" object returned has some methods you can call.
These are documented separately below.
函数可以使用的数据格式会在后面说明,plot返回对象有一些方法可供调用,在后面会分开介绍。
Note that in general Flot gives no guarantees if you change any of the
objects you pass in to the plot function or get out of it since
they're not necessarily deep-copied.
另外请注意,flot不保证plot函数内的对象被修改或删除后仍然能正常工作(废话)。
Data Format
数据格式
-----------
The data is an array of data series:
flot的数据是一个数列数组(plot函数中的data参数:每条曲线一个data项参数,绘制多条曲线时,是一个数组,每个数组元素是一条曲线的data项参数):
[ series1, series2, ... ]
A series can either be raw data or an object with properties. The raw
data format is an array of points:
数列可以是原始数据,也可以是数据对象,原始数据格式是由一组表示数据点的坐标值的数组构成:
[ [x1, y1], [x2, y2], ... ]
<
[ [1, 3], [2, 14.01], [3.5, 3.14] ]
Note that to simplify the internal logic in Flot both the x and y
values must be numbers (even if specifying time series, see below for
how to do this). This is a common problem because you might retrieve
data from the database and serialize them directly to JSON without
noticing the wrong type. If you're getting mysterious errors, double
check that you're inputting numbers and not strings.
请注意,flot的纵横坐标值都必须是数字(即使用时间数列也是,后面会介绍到),
这是个很常见的错误,因为你很可能从
数据库获取数据后没有检查数据类型就直接转化成json对象使用。
如果你觉得遇到了莫名其妙的错误,请确认一下你输入的是数字而不是字符串。
If a null is specified as a point or if one of the coordinates is null
or couldn't be converted to a number, the point is ignored when
drawing. As a special case, a null value for lines is interpreted as a
line segment end, i.e. the points before and after the null value are
not connected.
如果坐标为值为空 ,或者其中的一个坐标值为空,或者不是数字,或者说不能转换为数字,那么这个节点将被忽略,
并且该节点前后的2个节点之间不会使用直线来连接。
Lines and points take two coordinates. For bars, you can specify a
third coordinate which is the bottom of the bar (defaults to 0).
解方程组的步骤折线图和散点图每个节点有2个参数,直方图则有3个参数,第三个参数来指定直方图的底部位置(缺省值是0)。
The format of a single series object is as follows:
单个图表对象的数据格式参数如下所示:
{
color: color or number  //颜
data: rawdata  //数据
label: string  //曲线名称
lines: specific lines options  //折线图坐标参数
bars: specific bars options  //直方图坐标参数
points: specific points options  //散点图坐标参数
xaxis: 1 or 2  //使用哪一条X轴,如果某条数轴没有被任何一条曲线使用,该数轴不会在图表上出现
yaxis: 1 or 2  //使用哪一条Y轴
clickable: boolean  //允许监听鼠标点击事件
hoverable: boolean  //允许监听鼠标悬停事件
shadowSize: number //曲线阴影
}
You don't have to specify any of them except the data, the rest are
options that will get default values. Typically you'd only specify
label and data, like this:
一般情况下你无须设置每一个参数, 你只需要设置其中几个特定的参数即可,其他参数会使用默认值。例如:
{
label: "y = 3",
data: [[0, 3], [10, 3]]
}
The label is used for the legend, if you don't specify one, the series
代码生成器will not show up in the legend.
label用于指定曲线名称,如果没有设置label的值,图表标题区域不会出现。
If you don't specify color, the series will get a color from the
auto-generated colors. The color is either a CSS color specification
(like "rgb(255, 100, 123)") or an integer that specifies which of
auto-generated colors to select, e.g. 0 will get color no. 0, etc.
如果没有设置曲线颜,程序会自动采用默认颜(options项里的colors数列)。颜值可以是CSS颜格式(RGB格式、16进制颜、WEB通用颜名),
还可以是数字编号,数字编号表示颜数列里面颜的编号。
The latter is mostly useful if you let the user add and remove series,
in which case you can hard-code the color index to preven
t the colors
from jumping around between the series.
如果你允许用户重置或删除曲线,后者会比较有用,你可以在代码里面设置曲线使用的默认颜的序号防止相同颜在不用曲线间重复出现。
The "xaxis" and "yaxis" options specify which axis to use, specify 2
to get the secondary axis (x axis at top or y axis to the right).
<, you can use this to make a dual axis plot by specifying
{ yaxis: 2 } for one data series.
xaxis" 和 "yaxis" 设置曲线使用的数轴(第二条X轴是顶部横轴,第二条Y轴是右边的纵轴),你可以使用这个属性制作双数轴曲线
"clickable" and "hoverable" can be set to false to disable
interactivity for specific series if interactivity is turned on in
the plot, see below.
"clickable" 和 "hoverable"用于关闭该曲线的鼠标点击效果或鼠标悬停效果,具体说明看后面。
(options中的"clickable" 或 "hoverable"设置为true时可以在某条曲线的data里设置"clickable" 或 "hoverable"为false,但options中设置为false时,不能在这里设置为true)
The rest of the options are all documented below as they are the same
as the default options passed in via the options parameter in the plot
commmand. When you specify them for a specific data series, they will
override the default options for the plot for that data series.
其他参数在后面介绍,他们与plot函数的"options"参数的设置项是一样的,
如果你为某条曲线在data里面设置了这些参数的值,他们会覆盖掉options的默认值。
Here's a complete example of a simple data specification:
下面是一个简单例子,设置了2条曲线的参数:
[ { label: "Foo", data: [ [10, 1], [17, -14], [30, 5] ] },
{ label: "Bar", data: [ [11, 13], [19, 11], [30, -7] ] } ]
Plot Options
plot的options参数
------------
All options are completely optional. They are documented individually
below, to change them you just specify them in an object, e.g.
options的所有选项都是可选的,他们都有默认值,后面会逐条对他们进行讲解,如果要修改这些选项的默认值你只需要明确指定他们的值即可,例如:
var options = {
series: {
lines: { show: true },
points: { show: true }
}
};
$.plot(placeholder, data, options);
Customizing the legend
legend:定制曲线图表标题
======================
legend: {
show: boolean
labelFormatter: null or (fn: string, series object -> string)
labelBoxBorderColor: color
noColumns: number
position: "ne" or "nw" or "se" or "sw"
margin: number of pixels or [x margin, y margin]
backgroundColor: null or color
backgroundOpacity: number between 0 and 1
container: null or jQuery object/DOM element/jQuery expression
wap广告联盟源码
}
The legend is generated as a table with the data series labels and
一个格子里面分成上下二格
small label boxes with the colo
r of the series. If you want to format
the labels in some way, e.g. make them to links, you can pass in a
function for "labelFormatter". Here's an example that makes them
clickable:
legend 用于生成图表标题,图表标题以表格的方式显示在曲线图上,内容包括每条曲线的名称及其对应颜,
如果你想定制图表标题的格式,比如做成超链接,你可以在"labelFormatter"项使用函数来定制,下面的例子把图表标题做成链接
labelFormatter: function(label, series) {
// series is the series object for the label  //series是名称为label的曲线的数据对象
return '<a href="#' + label + '">' + label + '</a>';
}
"noColumns" is the number of columns to divide the legend table into.
"noColumns" 用于设置legend表格的列数
"position" specifies the overall placement of the legend within the
plot (top-right, top-left, etc.) and margin the distance to the plot
edge (this can be either a number or an array of two numbers like [x,
y]). "backgroundColor" and "backgroundOpacity" specifies the
background. The default is a partly transparent auto-detected
background.
position:用于指定legend在曲线图内的位置,"ne"东北角,"se"东南 , "nw"西北 , "sw"西南
margin: 设置legend与曲线图边框的距离,可以是x y轴偏移量的数值对[x,y]也可以是单个数字,单个数字值表示相对x,y轴的偏移量使用相同的值
采用哪条X轴和Y轴作为参照物取决于position的值
backgroundColor: 设置legend的背景颜
backgroundOpacity: 设置legend背景的透明度
If you want the legend to appear somewhere else in the DOM, you can
specify "container" as a jQuery object/expression to put the legend
table into. The "position" and "margin" etc. options will then be
ignored. Note that Flot will overwrite the contents of the container.
如果你想把legend放在其他DOM元素内,可以为container设定一个值,
container的值可以是jQuery对象或表达式,例如:container: $("#showChartLegend"),把标题显示在id为showChartLegend的div或其他容器类标签内,
container为legend指定容器后,"position" 和 "margin" 等与图表相关的位置属性会被忽略,
另外请注意,container指定的容器内容会被覆盖掉。
Customizing the axes
数轴定制
====================
xaxis, yaxis, x2axis, y2axis: {
mode: null or "time"  //数轴是否为时间模式
min: null or number  //数轴最小值
max: null or number  //数轴最大值
autoscaleMargin: null or number  //按百分比为数轴延长一小段来缩放曲线以避免曲线最远的数据点出现在图表边框上
//延长的距离为单位刻度的整数倍,且刚好不小于(max-min)*number,其中min端增加1个刻度单位的长度,当对应数轴的min和max值至少一个为null时才生效
//其中一个特例是,如果数据点的最小值为0,则min端不增长数轴,数据点会出现的边框上
//对X轴,该值默认为null,对Y轴,该值默认为0.02
labelWidth: null or number
labelHeight: null or number
transform: null or fn: number -> number
inverseTransform: null or fn: number -> number
ticks: null or number or ticks array or (fn: range -> ticks array)
tickSize: number or array
minTickSize: number or array
tickFormatter: (fn: number, object -> string) or string
tickDecimals: null or number
}
All axes have the same kind of options. The "mode" option
determines how the data is interpreted, the default of null means as
decimal numbers. Use "time" for time series data, see the next section.
所有数轴都有相同的参数设置,mode为null表示数轴十进制,为time设置为时间轴
The options "min"/"max" are the precise minimum/maximum value on the
scale. If you don't specify either of them, a value will automatically
be chosen based on the minimum/maximum data values.
"min"/"max" 设置数轴最大值和最小值,如果没有明确指定他们,将自动使用数据中的最小值和最大值
The "autoscaleMargin" is a bit esoteric: it's the fraction of margin
that the scaling algorithm will add to avoid that the outermost points
ends up on the grid border. Note that this margin is only applied
when a min or max value is not explicitly set. If a margin is
specified, the plot will furthermore extend the axis end-point to the
nearest whole tick. The default value is "null" for the x axis and
0.02 for the y axis which seems appropriate for most cases.
"autoscaleMargin"的解释见上文
"labelWidth" and "labelHeight" specifies a fixed size of the tick
labels in pixels. They're useful in case you need to align several
plots.
"labelWidth" 和 "labelHeight" 用于设置数轴刻度标签的高宽,这个属性在你需要排列整齐几个图表的时候会派上用场。
"transform" and "inverseTransform" are callbacks you can put in to
change the way the data is drawn. You can design a function to
compress or expand certain parts of the axis non-linearly, e.g.
suppress weekends or compress far away points with a logarithm or some
other means. When Flot draws the plot, each value is first put through
the transform function. Here's an example, the x axis can be turned
into a natural logarithm axis with the following code:
"transform" and "inverseTransform" 是回调函数,用于改变数轴上的数据显示方式,
你可以设计一个函数来非线性地扩展或压缩数轴上的特定数据段
xaxis: {
transform: function (v) { return Math.log(v); },
inverseTransform: function (v) { p(v); }
}
Note that for finding extrema, Flot assumes that the transform
function does not reorder values (monotonic