图表配置
图表配置对应后台文件为/opt/opennms/etc/
chart-configuration.xml主要是通过JFreeChart插件来展示图表
1.1 添加操作系统统计图表
<!--柱状图 --> <tns:bar-chart name="sample-bar-chart5" variation="2d" domain-axis-label="Windows/Linux/Ubuntu" show-legend="true" plot-orientation="horizontal" draw-bar-outline="true" range-axis-label="个" show-urls="false" show-tool-tips="false"> <!-- name 随便起,尽可能有意义,不与其他名字重复 variation 2d or 3d plot-orientation:vertical垂直 horizontal水平 bug?(无明显作用) range-axis-label="个" 左面的单位 domain-axis-label 底部显示说明 --> <!--标题 --> <tns:title font="SansSerif" style="" value="操作系统" pitch="12" /> <!--font:字体 value:显示标题 pitch:字体大小--> <!--设置图片显示大小 --> <tns:image-size> <!--宽 --> <tns:hz-size> <tns:pixels>450</tns:pixels> </tns:hz-size> <!--高 --> <tns:vt-size> <tns:pixels>300</tns:pixels> </tns:vt-size> </tns:image-size> <!—经测试以下红色部分有和无在页面都没有任何变化 --> <tns:grid-lines visible="true"> <tns:rgb> <tns:red> <tns:rgb-color>255</tns:rgb-color> </tns:red> <tns:green> <tns:rgb-color>255</tns:rgb-color> </tns:green> <tns:blue> <tns:rgb-color>255</tns:rgb-color> </tns:blue> </tns:rgb> </tns:grid-lines> <tns:series-def number="1" series-name="Windows" use-labels="true" > <!-- number 柱形图第一个位置显示 series-name 名称与下面sql中的字段一样 --> <tns:jdbc-data-set db-name="opennms" sql="select 'Windows', count(*) from node WHERE operatingsystem ='Windows'" /> <!-- db-name 数据库名称 sql sql语句 注意字段和上面的匹配 --> <!--下面三个为红,绿,蓝三种基色,如果想要什么此柱形图显示什么颜色,可以通过配置以下三种基色来调整 --> <tns:rgb> <tns:red> <tns:rgb-color>255</tns:rgb-color> </tns:red> <tns:green> <tns:rgb-color>0</tns:rgb-color> </tns:green> <tns:blue> <tns:rgb-color>0</tns:rgb-color> </tns:blue> </tns:rgb> </tns:series-def> <tns:series-def number="2" series-name="Linux" use-labels="true" > <tns:jdbc-data-set db-name="opennms" sql="select 'Linux', count(*) from node WHERE operatingsystem ='Linux'" /> <tns:rgb> <tns:red> <tns:rgb-color>0</tns:rgb-color> </tns:red> <tns:green> <tns:rgb-color>255</tns:rgb-color> </tns:green> <tns:blue> <tns:rgb-color>0</tns:rgb-color> </tns:blue> </tns:rgb> </tns:series-def> <tns:series-def number="3" series-name="Ubuntu" use-labels="true" > <tns:jdbc-data-set db-name="opennms" sql="select 'Ubuntu', count(*) from node WHERE operatingsystem ='Ubuntu'" /> <tns:rgb> <tns:red> <tns:rgb-color>0</tns:rgb-color> </tns:red> <tns:green> <tns:rgb-color>0</tns:rgb-color> </tns:green> <tns:blue> <tns:rgb-color>255</tns:rgb-color> </tns:blue> </tns:rgb> </tns:series-def> </tns:bar-chart> |
1.2 测试举例
1.2.1颜色配置
<tns:red> <tns:rgb-color>100</tns:rgb-color> </tns:red> |
显示结果
恢复255值显示如下:
显示Windows对应柱形图为粉色
对应结果:
1.2.2单位配置
修改显示单位如下:
显示结果
1.3 对应xsd文件
/var/opennms/xsds/chart-configuration.xsd
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xmlns.opennms.org/xsd/config/charts" xmlns:this="http://xmlns.opennms.org/xsd/config/charts" elementFormDefault="qualified">
<!-- This configuration file is used to generate JFreeChart graphics
All Chart Requirements: name: (unique named given to each chart defined) background-color: (hex)
Bar Chart Requirements: variation: (2d|3d) title: (string) sub-titles: value: (string) font: (i.e. SansSerif) style: (i.e. plain) pitch: (integer) position: (top, bottom) horizontal-alignment: (left, center, right) grid-line: paint: (hex) visible: (boolean) category-data-set: rows/columns (series/categories) value: series: category: series: (one or more) row-keys and values categories: (one or more) column-keys and values domain-axis: label: (string) grid-line: paint: (hex) visible: (true|false) lower-margin: (percent) category-margin: (percent) upper-margin: (percent) range-axis-label: (string) range-grid-line: paint: (hex) visible: (true|false) preferred-size: horizontal: (pixels) vertical: (pixels) range-axis-tick-units: (float|integer) plot-orientation: (vertical|horizontal) include-legend: (true|false) tool-tips: (true|false) urls: (true|false) draw-bar-outline: (true|false) series: value: (0-9999) paint: (hex gradiant) gradient:
Line Chart Requirements: (pretty much the same as bar) fill: use: (boolean) paint: (hex)
Pie Chart Requirements:
TODO: XYDataSets --> <element name="chart-configuration"> <complexType> <sequence> <element ref="this:bar-chart" minOccurs="0" maxOccurs="unbounded" /> </sequence> </complexType> </element>
<element name="bar-chart" > <complexType> <sequence> <element ref="this:title" minOccurs="1" maxOccurs="1" /> <element ref="this:image-size" minOccurs="1" maxOccurs="1" /> <element ref="this:sub-title" minOccurs="0" maxOccurs="unbounded" /> <element ref="this:grid-lines" minOccurs="0" maxOccurs="1" /> <element ref="this:series-def" minOccurs="0" maxOccurs="unbounded" /> <element ref="this:plot-background-color" minOccurs="0" maxOccurs="1" /> <element ref="this:chart-background-color" minOccurs="0" maxOccurs="1" /> </sequence> <attribute name="name" type="string" use="required" /> <attribute name="domain-axis-label" type="string" use="required" /> <attribute name="range-axis-label" type="string" use="required" /> <attribute name="sub-label-class" type="string" use="optional" /> <attribute name="series-color-class" type="string" use="optional" /> <attribute name="draw-bar-outline" type="boolean" use="optional" default="true"/> <attribute name="show-legend" type="boolean" use="optional" default="true"/> <attribute name="show-tool-tips" type="boolean" use="optional" default="false"/> <attribute name="show-urls" type="boolean" use="optional" default="false"/> <attribute name="variation" use="optional" > <simpleType> <restriction base="string"> <pattern value="(2d|3d)" /> </restriction> </simpleType> </attribute> <attribute name="plot-orientation" use="optional" > <simpleType> <restriction base="string"> <pattern value="(horizontal|vertical)" /> </restriction> </simpleType> </attribute> </complexType> </element>
<element name="series-def" > <complexType> <sequence> <element ref="this:jdbc-data-set" minOccurs="1" maxOccurs="1" /> <element ref="this:rgb" minOccurs="0" maxOccurs="1" /> </sequence> <attribute name="number" use="required" > <simpleType> <restriction base="int"> <minInclusive value="1"/> </restriction> </simpleType> </attribute> <attribute name="series-name" type="string" use="required" /> <attribute name="use-labels" type="boolean" use="optional" default="true" /> </complexType> </element>
<element name="jdbc-data-set" > <complexType> <attribute name="db-name" type="string" use="required" /> <attribute name="sql" type="string" use="required" /> </complexType> </element>
<element name="plot-background-color"> <complexType> <sequence> <element ref="this:rgb" minOccurs="0" maxOccurs="1" /> </sequence> </complexType> </element>
<element name="chart-background-color"> <complexType> <sequence> <element ref="this:rgb" /> </sequence> </complexType> </element>
<element name="grid-lines"> <complexType> <sequence> <element ref="this:rgb" minOccurs="0" maxOccurs="1" /> </sequence> <attribute name="visible" type="boolean" use="required" /> </complexType> </element>
<!-- select severity, count(*) as count from alarms group by severity order by severity desc -->
<element name="sub-title" > <complexType> <sequence> <element ref="this:title" minOccurs="1" maxOccurs="1"/> </sequence> <attribute name="position" use="optional" > <simpleType> <restriction base="string" > <pattern value="(top|bottom)" /> </restriction> </simpleType> </attribute> <attribute name="horizontal-alignment" use="optional" > <simpleType> <restriction base="string" > <pattern value="(left|center|right)" /> </restriction> </simpleType> </attribute> </complexType> </element>
<element name="title" > <complexType> <sequence> <element ref="this:rgb" minOccurs="0" maxOccurs="0" /> </sequence> <attribute name="value" type="string" use="required" /> <attribute name="font" type="string" use="optional" /> <attribute name="pitch" use="optional" > <simpleType> <restriction base="int"> <minInclusive value="1"/> </restriction> </simpleType> </attribute> <attribute name="style" type="string" use="optional" /> </complexType> </element>
<element name="hex-color" > <simpleType> <restriction base="string"> <pattern value="#([0-9a-f]{1,2}){3}" /> </restriction> </simpleType> </element>
<element name="rgb" > <complexType> <sequence> <element ref="this:red" minOccurs="1" maxOccurs="1" /> <element ref="this:green" minOccurs="1" maxOccurs="1" /> <element ref="this:blue" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element>
<element name="red" > <complexType> <sequence> <element ref="this:rgb-color" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element> <element name="green" > <complexType> <sequence> <element ref="this:rgb-color" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element> <element name="blue" > <complexType> <sequence> <element ref="this:rgb-color" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element>
<element name="rgb-color" > <simpleType> <restriction base="int" > <minInclusive value="0" /> <maxInclusive value="255" /> </restriction> </simpleType> </element>
<element name="image-size" > <complexType> <sequence> <element ref="this:hz-size" minOccurs="1" maxOccurs="1" /> <element ref="this:vt-size" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element>
<element name="vt-size" > <complexType> <sequence> <element ref="this:pixels" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element>
<element name="hz-size" > <complexType> <sequence> <element ref="this:pixels" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> </element>
<element name="pixels" > <simpleType> <restriction base="int" > <minInclusive value="1"/> </restriction> </simpleType> </element>
</schema> |
作者:儱剑阿攵
转载请注明链接:http://blog.youkuaiyun.com/awenluck/article/details/47360483