通过Google Chart Tools提供的图表功能实现如下:
地址如下:
http://code.google.com/intl/zh-CN/apis/chart/interactive/docs/gallery/gauge.html
效果如下图:
代码如下:
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows([
['Memory', 80],
['CPU', 55],
['Network', 68]
]);
var options = {
width: 400, height: 120,
redFrom: 90, redTo: 100,
yellowFrom:75, yellowTo: 90,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id='chart_div'></div>
</body>
</html>
Loading
The google.load
package name is "gauge"
google.load('visualization', '1', {packages: ['gauge']});
The visualization's class name is google.visualization.Gauge
var visualization = new google.visualization.Gauge(container);
Data Format
Each numeric value is displayed as a gauge. Two alternative data formats are supported:
- Two columns. The first column should be a string, and contain the gauge label. The second column should be a number, and contain the gauge value.
- Any number of numeric columns. The label of each gauge is the column's label.
Configuration Options
Name
Type
Default
Description
animation.duration |
number |
400 |
The duration of the animation, in milliseconds. For details, see the animation documentation. |
animation.easing |
string |
'linear' |
The easing function applied to the animation. The following options are available:
- 'linear' - Constant speed.
- 'in' - Ease in - Start slow and speed up.
- 'out' - Ease out - Start fast and slow down.
- 'inAndOut' - Ease in and out - Start slow, speed up, then slow down.
|
greenColor |
string |
'#109618' |
The color to use for the green section, in HTML color notation. |
greenFrom |
number |
none |
The lowest value for a range marked by a green color. |
greenTo |
number |
none |
The highest value for a range marked by a green color. |
height |
number |
Container's width |
Height of the chart in pixels. |
majorTicks |
Array of strings |
none |
Labels for major tick marks. The number of labels define the number of major ticks in all gauges. The default is five major ticks, with the labels of the minimal and maximal gauge value. |
max |
number |
100 |
The maximal value of a gauge. |
min |
number |
0 |
The minimal value of a gauge. |
minorTicks |
number |
2 |
The number of minor tick section in each major tick section. |
redColor |
string |
'#DC3912' |
The color to use for the red section, in HTML color notation. |
redFrom |
number |
none |
The lowest value for a range marked by a red color. |
redTo |
number |
none |
The highest value for a range marked by a red color. |
width |
number |
Container's width |
Width of the chart in pixels. |
yellowColor |
string |
'#FF9900' |
The color to use for the yellow section, in HTML color notation. |
yellowFrom |
number |
none |
The lowest value for a range marked by a yellow color. |
yellowTo |
number |
none |
The highest value for a range marked by a yellow color. |
Methods
Method
Return Type
Description
draw(data, options) |
none |
Draws the chart. |
clearChart() |
none |
Clears the chart, and releases all of its allocated resources. |
Events
No triggered events.
Java 实现DashBoard:
package com.easyway.dashbroad;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Point;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.dial.DialBackground;
import org.jfree.chart.plot.dial.DialCap;
import org.jfree.chart.plot.dial.DialPlot;
import org.jfree.chart.plot.dial.DialTextAnnotation;
import org.jfree.chart.plot.dial.DialValueIndicator;
import org.jfree.chart.plot.dial.StandardDialFrame;
import org.jfree.chart.plot.dial.StandardDialRange;
import org.jfree.chart.plot.dial.StandardDialScale;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.StandardGradientPaintTransformer;
/**
*
* @Title:
* @Description: JFreeChart实现Dashboard功能
* @Copyright:Copyright (c) 2011
* @Company:易程科技股份有限公司
* @Date:2011-4-11
* @author longgangbai
* @version 1.0
*/
public class DashboardApp {
public String getDial(String warnName,double warnValue) {
// 数据集合对象 此处为DefaultValueDataset
DefaultValueDataset dataset = new DefaultValueDataset();
// 当前指针指向的位置,即:我们需要显示的数据
dataset = new DefaultValueDataset(warnValue);
// 实例化DialPlot
DialPlot dialplot = new DialPlot();
dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
// 设置数据集合
dialplot.setDataset(dataset);
// 开始设置显示框架结构
StandardDialFrame simpledialframe = new StandardDialFrame();
simpledialframe.setBackgroundPaint(Color.lightGray);//Color.lightGray //仪表盘边框内部颜色
simpledialframe.setForegroundPaint(Color.darkGray);//Color.darkGray //仪表盘边框外部颜色
dialplot.setDialFrame(simpledialframe);
// 结束设置显示框架结构,表盘颜色 从最上部 白色 过渡到最下部的蓝色
GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(229,229,229), new Point(), new Color(229,229,229));
DialBackground dialbackground = new DialBackground(gradientpaint);
dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
dialplot.setBackground(dialbackground);
// 设置显示在表盘中央位置的信息
DialTextAnnotation dialtextannotation = new DialTextAnnotation(warnName);
dialtextannotation.setFont(new Font("宋体", 1, 16));
dialtextannotation.setRadius(0.69999999999999996D);
dialplot.addLayer(dialtextannotation);
// 设置刻度范围(绿色)
if(warnValue==0){
StandardDialRange standarddialrange2 = new StandardDialRange(0D, 100D,Color.green);
standarddialrange2.setInnerRadius(0.52000000000000002D);
standarddialrange2.setOuterRadius(0.55000000000000004D);
dialplot.addLayer(standarddialrange2);
}else if(warnValue>0&&warnValue<=100){// 设置刻度范围(橘黄色)
StandardDialRange standarddialrange1 = new StandardDialRange(0D, 100D,Color.orange);
standarddialrange1.setInnerRadius(0.52000000000000002D);
standarddialrange1.setOuterRadius(0.55000000000000004D);
dialplot.addLayer(standarddialrange1);
}else if(warnValue>100&&warnValue<=1000){// 设置刻度范围(红色)
StandardDialRange standarddialrange = new StandardDialRange(0D, 1000D,Color.red);
standarddialrange.setInnerRadius(0.52000000000000002D);
standarddialrange.setOuterRadius(0.55000000000000004D);
dialplot.addLayer(standarddialrange);
}else if(warnValue>1000){// 设置刻度范围(红色)
StandardDialRange standarddialrange = new StandardDialRange(0D, 10000D,Color.red);
standarddialrange.setInnerRadius(0.52000000000000002D);
standarddialrange.setOuterRadius(0.55000000000000004D);
dialplot.addLayer(standarddialrange);
}
//指针指示框 ,仪表盘中间的小方框
DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
dialvalueindicator.setFont(new Font("宋体", 1, 14));
dialvalueindicator.setOutlinePaint(new Color(229,229,229));
dialvalueindicator.setBackgroundPaint(new Color(229,229,229));
dialvalueindicator.setRadius(0.39999999999999998D);
//dialvalueindicator.setPaint(Color.red);
dialplot.addLayer(dialvalueindicator);
/*
* StandardDialScale 方法
* 参数1 开始数值 类似手表 开始 0点
* 参数2 结束数值 类似手表 结束 12点
* 参数5 间隔差值 类似手表 间隔差值5分钟
* 参数6 间隔数量 类似手表 1点到2点 有4个间隔点
*/
//如果 预警条数少于 100条,开度从 0 至 100 ,间隔 10
double startPosition=0D; //开度 0
double endPosition=100D; //开度 100
double skipValue=10D; //间隔 10
if(warnValue>100&&warnValue<1000){
endPosition=1000D;
skipValue=100D;
}else if(warnValue>=1000){
endPosition=10000D;
skipValue=1000D;
}
//刻度盘设置
StandardDialScale standarddialscale = new StandardDialScale(startPosition, endPosition,-120D, -300D, skipValue, 4);
standarddialscale.setTickRadius(0.88D);//设置半径
standarddialscale.setTickLabelOffset(0.14999999999999999D);
standarddialscale.setTickLabelFont(new Font("Dialog", 0, 10));//刻度盘数字大小
// 注意是 dialplot.addScale()不是dialplot.addLayer()
dialplot.addScale(0, standarddialscale);
// 设置指针
org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer();
dialplot.addLayer(pointer);
// 实例化DialCap
DialCap dialcap = new DialCap();
dialcap.setRadius(0.10000000000000001D);
dialplot.setCap(dialcap);
// 生成chart对象
JFreeChart jfreechart = new JFreeChart(dialplot);
// 3、设定参数输出结果,首先在 项目/WEB-INF/classes/,添加WarnImages文件夹
String filePath="D:/"+System.currentTimeMillis()+".jpeg";//动态文件名 相对
FileOutputStream file = null;
try {
file = new FileOutputStream(filePath);
ChartUtilities.writeChartAsJPEG(file, 1.0f, jfreechart, 200, 200,null);//200,200 图片大小
} catch (IOException e) {
e.printStackTrace();
} // 生成图片
finally {
try {
file.close();// 最后关闭文件流
} catch (IOException e) {
e.printStackTrace();
}
}
return filePath;
}
public static void main(String[] args) {
System.out.println(new DashboardApp().getDial("测试预警",80.0));
}
}
分享到:
相关推荐
谷歌地图 ngTables Chart.js sparkline 自定义开关按钮 自定义单选按钮和复选框 定价表页面 锁定屏幕和登录页面 404错误页面 500错误页面 集成WYSIWYG编辑器(CKEditor) 邮箱 日历 时间表 搜索结果 清单 用户配置文件...
使用Google表格更新您的实时信息中心 多年来,人们一直在使用电子表格来保存和理解数据。 一旦数据增长到成百上千个单元,就很难快速,轻松地掌握它们。 那么,如果我们有一个Google表格可以自动更新您的仪表板,使...
Chartjs Charts Brite Charts Apex Charts Select2, Date Range Picker, Input Mask included Bootstrap form wizard Timepickers Spinner Max Length Validator Advanced Datatables Dragula – Simple Drag and ...
项目目的该项目旨在以可访问,信息丰富且交互式的格式显示来自SpaceX 数据。...激发人们对SpaceX未来活动的兴趣3 3范围功能规格在考虑功能规范时,我研究了SpaceX API的现有图形实现。 SpaceX提供了各种各样的数据(1
基于带有 OAuth2、图表和表格的 Google Analytics Reporting API v4 的自定义 Google Analytics Dashboard。 使用的技术 在本地运行应用程序 克隆这个 repo 在创建项目 启用 Google Analytics 报告 API。 配置 ...
NextJS Material Dashboard是一个免费的Material-UI,NextJS和React Admin,其设计灵感来自Google的Material Design。 我们很高兴通过易于使用且美观的组件来介绍我们对材料概念的看法。 NextJS Material Dashboard...
SocketIO是一个精简JavaScript库,用于实现快速的实时通信。 Firebase是Google的云后端即服务。 Firebase提供了许多单独的服务,包括身份验证,实时数据库,Cloud Firestore,Cloud Functions等。 此入门项目实现...
执行gulpfile.js代码以识别JavaScript代码中的任何潜在错误,并在安装后自动注入Bower依赖项。 终端标签1: npm install bower install python -m SimpleHTTPServer 3000 终端标签2: gulp 在process_data中...
个别商店无法从其他位置访问信息 以下是DSR展开后的外观示例:方法电子表格链接到Google表单,该表单通过每个位置的主副本生成的预填充链接提交。 这使公司办公室可以一次查看所有位置,而商店却看不到彼此的信息。...
ct-black-dashboard-pro-react:Black Dashboard PRO React:高级Boostrap和Reactstrap管理模板
WgBoard - Responsive Admin/Dashboard Template 15+页面 10+插件 jQuery 2.2.0 jQuery UI Bootstrap 3.3.7 Roboto Google Font Font Awesome Icons Elegant Icons Themify icons Chart.js jQuery Vector Maps ...
安装 yarn add google-lighthouse-puppeteer-cli-dashboard -gornpm install google-lighthouse-puppeteer-cli-dashboard --global用法 $> lp-dashboard -h Options -f, --file file Path to your summary.j
Vue Admin Dashboard是建立在 , 和之上的漂亮资源。 它将帮助您立即开始开发仪表板。 使用仪表板非常简单,但是需要Javascript, 和基础知识。 Vuetify是完全根据材料设计规范开发的。 每个组件都是手工制作的,...
git clone https://github.com/nenadV91/react-dashboard.git npm install npm start 建造 npm run build 更改主题 转到src/assets/styles/variables/_variables.scss并取消注释所需的主题 一次只应激活一个 / / ...
我写了Space Dashboard是一个小小的React应用程序,用来告诉自己使用React JS的基础知识。 它利用了各种NASA API(当天的照片,ISS位置,NASA Insight),其密钥未包含在此存储库中。 (因此有必要获得自己的(免费...
openmrs-contrib-dashboard-groups ID Dashboard 的 Google Groups 集成模块注意: OpenMRS 不再使用 Google Groups,现在使用 。
Analytics资讯主页 该项目使用使用上 库来构建功能强大的分析仪表板网站。 它可以在和上成功运行。 该项目的一部分基于一个真正的商业软件项目,它通过从软件系统中主要是进行来构建统计信息。...
云开发人员仪表板 所有开发人员信息都直接在仪表板上 这是一个简单的项目,可让您在仪表板上...将js复制到js窗格 将CSS复制到CSS窗格 保存并享受 去做: 在项目列表上方添加警报面板 优化(如果可能)。 还不知道...
使用仪表板非常简单,但是需要Javascript, 和基础知识。我们创建它时考虑的是仪表板中您实际需要的东西。 Vuetify Material Dashboard包含精选和优化的Vuejs插件。一切都旨在相互配合。如您所见,您可以在上访问的...
Material admin模板对于商业用途主题是完全免费的,该主题使用google的实现库。 它不依赖任何JavaScript框架,旨在针对跨设备使用进行响应和优化。 所有组件都是使用CSS(scss),JavaScript(es6)和HTML5创建的。...