Adobe ColdFusion 8

cfchart

描述

生成并且显示一个chart。

类别

数据输出标签, 可扩展性标签

语法

<!--- This syntax uses an XML file or string to specify the chart style. --->
<cfchart
    style = "XML string|XML filename"> 
</cfchart>

或者

<!--- This syntax uses the attributes of the cfchart tag to specify the chart style. --->
<cfchart 
    backgroundColor = "hexadecimal value|web color" 
    chartHeight = "integer number of pixels" 
    chartWidth = "integer number of pixels" 
    dataBackgroundColor = "hexadecimal value|web color" 
    font = "font name" 
    fontBold = "yes|no" 
    fontItalic = "yes|no" 
    fontSize = "font size" 
    foregroundColor = "hexadecimal value|web color" 
    format = "flash|jpg|png" 
    gridlines = "integer number of lines" 
    labelFormat = "number|currency|percent|date" 
    markerSize = "integer number of pixels" 
    name = "string"
    pieSliceStyle = "solid|sliced" 
    scaleFrom = "integer minimum value" 
    scaleTo = "integer maximum value" 
    seriesPlacement = "default|cluster| stacked|percent" 
    show3D = "yes|no" 
    showBorder = "yes|no" 
    showLegend = "yes|no" 
    showMarkers = "yes|no" 
    showXGridlines = "yes|no" 
    showYGridlines = "yes|no" 
    sortXAxis = "yes|no" 
    tipBGColor = "hexadecimal value|web color" 
    tipStyle = "MouseDown|MouseOver|none"
    title = "title of chart"
    url = "onClick destination page" 
    xAxisTitle = "title text" 
    xAxisType = "scale|category"
    xOffset = "number between -1 and 1" 
    yAxisTitle = "title text" 
    yAxisType = "scale|category"
    yOffset = "number between -1 and 1">
</cfchart>

注: 你可以在attributeCollection 中指定这个标签的属性,作为一个结构的value,在attributeCollection 中指定结构的名称,并使用这个标签的属性名称作为这个结构的Keys

 

历史

ColdFusion 8:

  • cfdocument里的嵌入式Flash charts提供支持。
  • 为chart式样的文件添加新的属性showColumnLegend ,该属性showColumnLegend是位于charting\styles directory的一个XML文件。属性显示了每个点的入口,而且它只适用于包含一个single series的chart。showColumnLegend的值默认为true,如果想关掉这个功能,你可以修改所有chart 样式文件的设置,也可以使用一个惯例的style文件。

ColdFusion MX 7.01: 把文件改成state,这样fontSize属性就可以接受一个非整数的数字。

ColdFusion MX 7:

  • 添加了样式和标题属性。
  • 为 eight-digit hexadecimal值提供支持这样就可以指定 RGB颜色和透明度。
  • 移除旋转属性。

ColdFusion MX 6.1:

  • 添加了xAxisTypeyAxisType属性。
  • 改变了插值行为:这个标签现在在带有多系列的line charts上插补了数据点 。

ColdFusion MX: 添加了这个标签

属性

属性

必选/可选

默认

描述

BackgroundColor

可选

 

数据背景和chart边框之间区域的颜色,around labels and around the legend.

Hexadecimal 值或者支持的命名颜色,请看使用方法里面的命名表对于一个 hexadecimal 值来说, 可以这样使用: "##xxxxxx" 或者 "##xxxxxxxx", 这里 x = 0-9 or A-F; 使用了两个颜色标志或者一个都不用。

chartHeight

可选

240

Chart 的高度; 单位是整数的 pixels.

chartWidth

可选

320

Chart 的宽度; 单位是整数的 pixels.

dataBackgroundColor

可选

白色

chart 数据周围区域的颜色。

Hexadecimal 值或者支持的命名颜色r; 请看使用方法部分的命名清单。

对于一个hexadecimal 值, 使用"##xxxxxx" 或者 "##xxxxxxxx"的形式, 这里 x = 0-9 or A-F; 使用两个数字标志或者一个都不用.

font

可选

arial

text font的名字:

  • arial
  • times
  • courier
  • arialunicodeMS.如果你在UNIX上使用双字节字母,这个选项是必须的.

fontBold

可选

no

文字是否使用粗体 :

  • yes
  • no

fontItalic

可选 

no

是否把文字设置为楷体:

  • yes
  • no

fontSize

可选

11

字体大小。如果数字不是一个整数,ColdFusion会把数字归整为下一个整数。

foregroundColor

可选

black

文本颜色, 网格线, 和标签.

Hexadecima值或者支持的命名颜色;请看使用方法部分的命名清单.

对于一个 hexadecimal 值, 请使用 "##xxxxxx" 或者 "##xxxxxxxx"的形式, 这里 x = 0-9 or A-F; 使用两个数字标志或者一个都不用.

format

可选

flash

保存图表的文件格式

  • flash
  • jpg
  • png

gridlines

可选

10, including top and bottom

在x轴上显示的网格线的数量,整数。

labelFormat

可选

number

y轴的格式

  • number
  • currency
  • percent
  • date

markerSize

可选 

(Automatic)

轴线上的点的大小,整数

name

可选

 

页面变量名,字符串。产生二进制的图,并指定给指定的变量。压制chart显示。你可以使用cffile标签里的名字变量把chart写到文件里去。

pieSliceStyle

可选

sliced

使用于cfchartseries类型属性的值

  • solid: 把pie 显示为unsliced
  • sliced: 把pie显示为sliced

scaleFrom

可选

Determined by data

y轴上最小的值;整数

scaleTo

可选

Determined by data

y轴上最大的值;整数

seriesPlacement

可选

default

chart里面series的相关位置,这些位置有不止一个的数据series

  • default: ColdFusion基于图的类型决定了相对位置。
  • cluster
  • stacked
  • percent

show3D

可选

yes

是否显示 3D外形的chart。

  • yes
  • no

showBorder

可选

no

是否显示chart外部的边框

  • yes
  • no

showLegend

可选

yes

如果chart包含不止一个的数据series,是否显示legend

  • yes
  • no

showMarkers

可选

yes

是否在直线上,曲线上,散射图上的数据点显示标记,

  • yes
  • no

showXGridlines

可选

no

是否显示x轴上的gridlines

  • yes
  • no

showYGridlines

可选

yes

是否显示y轴上的gridlines

  • yes
  • no

sortXAxis

可选

no

是否在显示x轴上字母命令的列标签

  • yes
  • no

如果x轴的类型属性是scale的话,可以忽略。

style

可选

 

XML文件或者字符串可以用来指定chart的类型。

title

可选

 

标题

tipbgcolor

可选

white

tip的背景色. 只适用于 Flash格式的图文件。

Hexadecimal 值或支持的命名颜色,请看使用方法部分的命名清单。

对于一个 hexadecimal 值,请使用"##xxxxxx"的格式, where x = 0-9 or A-F; 使用两个数字标示或者一个也不用。

tipStyle

可选

mouseOver

定义了一个反应:一个跳出框提示当前chart元素的信息。

  • mouseDown: 如果用户把游标移到元素上或者点击鼠标就会显示。只适用于 Flash 格式的图文件。 (对于其他的格式,这个可选功能和mouseOver是一样的。)
  • mouseOver: 如果用户把游标移动在元素上就会显示。
  • none: 不支持显示。

url

可选

 

如果用户在一个数据series里点击了该项目,URL就会打开onClick的目标页面。

你可以在URL字符串里指定变量;ColdFusion可以通过变量的当前值。

  • $VALUE$: 选择栏的值。如果没有这个值,值就是一个空的字符串。
  • $ITEMLABEL$: 选择栏的标签,如果没有的话,值就是一个空的字符串。
  • $SERIESLABEL$:被选择的series标签.如果没有,则是一个空字符串
    例如:
    "somepage.cfm?item=$ITEMLABEL$&series=$SERIESLABEL$&value=$VALUE$
  • "javascript:...": 处理一个客户端script。

xAxisTitle

可选

 

显示在x轴上的标题,文本格式。

xAxisType

可选

category

x轴是显示数据还是数字

  • category: x轴上显示了数据类别,数据根据x轴的属性类别进行分类。
  • scale: x 轴上是数字。所有的cfchartdata项目属性值都必须是数字。x轴会自动根据数字分类。

xOffset

可选

0.1

一些units可以用来以角度和横向联合的不同方式显示chart。只适用于 show3D="yes"的情况。数字可以是-1到1,这里-1指的是左转90度 ,1指的是右转90。

yAxisTitle

可选

 

y轴的标题,文本格式。

yAxisType

可选

category

目前还没有具体作用,因为y轴总是用来表示数据值。

yOffset

可选

0.1

unit的值,用来以角度的方式显示chart。只适用于 show3D="yes"的情况。数字可以是-1到1,这里-1指的是左转90度 ,1指的是右转90。

用途

cfchart标签定义了一个container ,在container里图会显示它的高度,宽度,背景色,标签(labels)等等。 cfchartseries标签定义了chart 的类型,包括: bar, line, pie, 等等。 cfchartdata 标签定义了一个 data point。

数据以以下方式传递给 cfchartseries 标签:

  • 以 query的形式。
  • 使用cfchartdata标签,以一个data points的形式。

字体类型的值是 ArialUnicodeMS以下规则适用:

  • 在Windows系统里, 允许 Flash charts (type = "flash") 来 使用双字节来设定,你必须选择这个值。
  • 在UNIX系统里,对于所有类型的值,要 使用双字节来设定, 你都必须选择这个值。
  • 如果这个值已经选择了,那么 fontBoldfontItalic 属性就没有作用了。

以下的表格列出了 W3C HTML 4 ,它可以被颜色属性接受,名字叫做 color value 或者 hexadecimal 值:

Color name

RGB value

Aqua

##00FFFF

Black

#000000

Blue

##0000FF

Fuchsia

##FF00FF

Gray

##808080

Green

##008000

Lime

##00FF00

Maroon

##800000

Navy

##000080

Olive

##808000

Purple

##800080

Red

##FF0000

Silver

##C0C0C0

Teal

##008080

White

##FFFFFF

Yellow

##FFFF00

对于所有其他的r color values, 你都必须输入 hexadecimal 值。你可以输入一个 six-digit 值,它指定了RGB 值,或是输入 一个eight-digit 值, 它指定了RGB 值和 and the 透明度。最先的hexadecimal 值的两个 digits指定了透明度的度数, 00 和 FF之间的值都是可用的。

更多流行浏览器支持的color names请看 www.w3.org/TR/css3-color

无论char是否缓存在内存里,无论多少chart被缓存,无论多少的chartColdFusion可以马上运行,你都可以进行具体的指定。要在 ColdFusion Administrator里进行这些设置,你可以选择Server Settings > Charting.

ColdFusion 8 让你可以在一个使用cfdocument标签的PDF 文件中嵌入Flash chart。例如:

<cfdocument format="pdf">
...
<!--- Flash chart embedded here. --->
    <cfchart format="flash" xaxistitle="Department" yaxistitie="Salary Average">
        <cfchartseries type="bar" query="DataTable" itemcolumn="Dept_Name"
            valuecolumn="avgSal">
            <cfchardata item="Facilities" value="35000">
        </cfchartseries>
    </cfchart>
</cfdocument>

例子

<!---The following example analyzes the salary data in the cfdocexamples database and
    generates a bar chart showing average salary by department. The body of the 
    cfchartseries tag includes one cfchartdata tag to include data that is not available 
    from the query. --->

<!--- Get the raw data from the database. --->
<cfquery name="GetSalaries" datasource="cfdocexamples">
    SELECT Departmt.Dept_Name, 
        Employee.Dept_ID, 
        Employee.Salary
    FROM Departmt, Employee
    WHERE Departmt.Dept_ID = Employee.Dept_ID
</cfquery>

<!--- Use a query of queries to generate a new query with --->
<!--- statistical data for each department. --->
<!--- AVG and SUM calculate statistics. --->
<!--- GROUP BY generates results for each department. --->
<cfquery dbtype = "query" name = "DataTable">
    SELECT Dept_Name,
    AVG(Salary) AS avgSal,
    SUM(Salary) AS sumSal
    FROM GetSalaries
    GROUP BY Dept_Name
</cfquery>

<!--- Reformat the generated numbers to show only thousands. --->
<cfloop index = "i" from = "1" to = "#DataTable.RecordCount#">
    <cfset DataTable.sumSal[i] = Round(DataTable.sumSal[i]/1000)*1000>
    <cfset DataTable.avgSal[i] = Round(DataTable.avgSal[i]/1000)*1000>
</cfloop>

<h1>Employee Salary Analysis</h1> 
<!--- Bar graph, from Query of Queries --->
<cfchart format="flash" 
    xaxistitle="Department" 
    yaxistitle="Salary Average"> 

<cfchartseries type="bar" 
    query="DataTable" 
    itemcolumn="Dept_Name" 
    valuecolumn="avgSal">

<cfchartdata item="Facilities" value="35000">

</cfchartseries>
</cfchart>