需要引入jquery.flot.min.js,提供下载
1、第一步,现在Html中定义一个DIV
<div id="placeholder" style="width:900px;height:250px"></div>
2、Js代码,设置绘制图像样式、数据等,sin是数据信息,我项目中使用的是struts2,所有使用${attr.view.abrasion};获取曲线数据
for循环部分是画了一条直线,蓝色的
同时设置了鼠标跟随的动态提示
$(function () {
var cos = [];
//var sin = ${attr.view.abrasion};
var sin = [[399.02637,30.346779],[395.02637,30.347057],[390.6585,30.577139],[386.55945,30.840343],[382.3095,30.952269],[378.2246,31.190714],[373.9902,31.37474],[369.91946,31.730484],[365.85544,31.798178],[361.64392,32.083477],[357.594,32.42432],[353.39792,32.471355],[349.36206,32.49643],[345.18143,32.655766],[341.15967,32.80746],[336.99442,32.961533],[332.98672,33.309525],[328.9858,33.369335],[324.84332,33.660122],[320.41394,33.821957],[316.2877,33.960262],[311.87488,34.25151],[307.7649,34.428562],[303.36865,34.738857],[298.8366,34.78687],[294.4579,35.070305],[290.08762,35.146114],[286.01935,35.48213],[281.66586,35.762764],[277.17996,35.797653],[272.84415,36.115673],[268.51694,36.331394],[264.49075,36.37741],[260.18054,36.924973],[255.87895,36.99195],[251.8778,37.0495],[247.59338,37.41077],[243.3177,37.614735],[238.91556,37.648438],[234.65808,37.9302],[230.40944,38.155457],[226.03633,38.161896],[221.8061,38.477707],[217.58482,38.657146],[213.37253,38.64594],[209.03838,38.63915],[204.84477,38.941635],[200.66028,39.07185],[196.35587,38.78464],[192.19028,38.90784],[188.03392,39.072952],[183.88683,38.908165],[179.62233,38.791584],[175.49446,38.93355],[171.37596,38.887493],[167.26689,38.799892],[163.04292,38.457005],[158.9534,38.370205],[154.87341,38.34476],[150.80301,38.58203],[146.74223,38.45967],[142.56963,38.18601],[138.5288,38.19337],[134.4977,38.43728],[130.4764,38.28967],[126.46491,38.361256],[122.4633,38.071995],[118.35345,37.90602],[113.97466,37.856453],[109.60796,37.80679],[105.253395,37.75703],[100.91102,37.558903],[96.85882,37.28572],[92.54042,37.236176],[88.23436,37.353455],[83.94067,37.50503],[79.659386,37.454777],[75.39058,37.404446],[71.13428,37.352993],[66.890526,37.297512],[62.65937,37.027702],[58.246582,36.839046],[54.246582,36.802048],[50.246582,36.76979],[46.246582,36.74774],[42.246582,36.74163],[38.246582,36.757328],[34.246582,36.800266],[30.24658,36.874928],[26.24658,36.984455],[22.24658,37.130375],[18.24658,37.312428],[14.246581,37.528526],[10.246581,37.77479],[6.2465806,38.04574],[2.2465806,38.33449],[-1.7534193,38.63314],[-5.7534194,38.933132],[-9.753419,39.225716],[-13.753419,39.50244],[-17.75342,39.755657],[-21.75342,39.979008],[-25.75342,40.167873],[-29.75342,40.319798],[-33.753418,40.434772],[-37.753418,40.515438],[-41.753418,40.567097],[-45.753418,40.597557],[-49.753418,40.616734],[-53.753418,40.635796],[-57.753418,40.66862],[-61.874634,40.713593],[-66.073006,40.7631],[-70.282585,40.785324],[-74.50337,40.63114],[-78.63233,40.895344],[-82.875,40.953335],[-87.12884,41.0023],[-91.39382,41.05116],[-95.669945,41.099907],[-99.9572,41.14854],[-104.25556,41.10104],[-108.45855,40.847424],[-112.77859,40.881504],[-117.10968,40.929176],[-121.45182,40.976727],[-125.80499,41.024155],[-130.16917,41.071457],[-134.54434,41.18699],[-138.93048,41.548653],[-143.32756,41.623344],[-147.7356,41.65669],[-152.15453,41.564335],[-156.58435,41.904373],[-160.91245,41.842453],[-164.91786,41.19119],[-168.93205,41.296795],[-172.95497,41.33896],[-176.98663,41.381],[-181.02701,41.423878],[-185.07608,41.46686],[-189.13382,41.50852],[-193.20021,41.550045],[-197.27524,41.591446],[-201.35889,41.632717],[-205.45113,41.737873],[-209.55193,41.088867],[-213.66129,41.17109],[-217.77917,41.976994],[-221.78578,41.829514],[-225.92017,41.869953],[-230.06302,41.91026],[-234.2143,41.95042],[-238.374,41.99044],[-242.54207,41.03032],[-246.7185,41.070053],[-250.90329,41.109985],[-255.09639,41.243988],[-259.29776,41.58643],[-263.5074,41.64921],[-267.72528,41.688553],[-271.95135,41.7693],[-276.1856,41.98821],[-280.428,41.96723],[-284.67853,41.84435],[-288.93713,41.882904],[-293.20383,41.921295],[-297.47852,41.959522],[-301.76123,41.05969],[-306.1819,41.94378],[-310.35056,41.02404],[-314.7881,41.12047],[-319.10303,41.157864],[-323.4258,41.384026],[-327.7564,41.48421],[-332.0948,41.563343],[-336.44092,41.729153],[-340.79477,41.768654],[-345.1563,41.81064],[-349.52548,41.14591],[-353.90225,41.97994],[-358.28662,41.064106],[-362.32697,41.342125],[-366.72607,41.377647],[-371.13266,41.19025],[-375.54666,41.86996],[-379.96808,41.203224],[-384.39685,41.186768],[-388.83295,41.961697],[-393.417,41.267307],[-397.86816,41.38517]];
for (var i = -400; i <=400; i++) {
cos.push([i, 23.0]);
}
var plot = $.plot(
$("#placeholder"),
[
{ color: 'red', data: sin, label: "滑板磨耗", lines: { show: true, lineWidth: 2}, points: {radius: 0.2}},
{ color: 'blue', data: cos, label: "合格标准",lines: { show: true}, hoverable: false, clickable: false}
],
{
grid: { hoverable: true, clickable: true },
xaxis: {min: -400, max: 400},
yaxis: { min: 0, max: 55, tickSize: 5}
}
);
var previousPoint = null;
$("#placeholder").bind("plothover",
function (event, pos, item) {
//$("#x").text(pos.x.toFixed(2));
//$("#y").text(pos.y.toFixed(2));
//if ($("#enableTooltip:checked").length > 0) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY, "位置:" + x + "</br> 剩余:" + y + "mm");
}
}else {
$("#tooltip").remove();
previousPoint = null;
}
//}
}
);
//显示坐标跟随
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #000',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(1);
}
});
曲线图:
- 大小: 14.5 KB
分享到:
相关推荐
总结来说,jQuery Flot是绘制时间曲线图的强大工具,它通过简单易用的API和丰富的配置选项,使开发者能够快速创建出交互性强、视觉效果良好的时间序列图表。无论是静态展示还是动态更新,Flot都能胜任。通过深入学习...
本篇文章将深入探讨如何利用Flot库在网页中创建简单的曲线图。 首先,我们需要了解Flot的基本结构。Flot的绘图过程主要分为两个步骤:准备数据和配置选项。数据通常是以数组的形式存储,每个数组元素代表一个数据点...
在这个案例中,我们将深入探讨如何使用Flot库创建动态曲线图,即随着时间的推移,图表数据会持续更新。 1. **Flot库的安装与引入** 在开始之前,你需要先下载或通过npm获取Flot库。如果你选择使用CDN,可以将以下...
在这个特定的案例中,我们关注的是如何使用Flot来创建可选显示的曲线图。 Flot的主要优点在于其灵活性和易用性。它提供了丰富的选项来定制图形的外观和行为,比如线条颜色、宽度、点的形状和大小,甚至可以设置数据...
在使用Flot绘制柱形图时,你需要准备一组数据,每组数据通常包含x轴和y轴的值。例如: ```javascript var data = [ {label: "数据1", data: [[1, 10]], bars: {show: true}}, {label: "数据2", data: [[2, 20]], ...
Flot支持多种图表类型,包括线条图(lines)、折线图(points)、柱状图(bars)以及饼图(pie)。每种图表都有不同的配置选项,可以通过设置`series`参数来调整。 **3. 数据格式** Flot接受两种基本的数据格式:...
Flot是一款基于jQuery的数据可视化库,它主要用于在网页上绘制高质量的图表,包括折线图、柱状图、饼图等。"flot折线图"这个主题涉及到的知识点主要集中在如何使用Flot来创建和定制各种折线图。下面我们将深入探讨...
- 使用 jQuery 的 `$.plot()` 函数将数据绘制成图,传入 canvas 元素的选择器和数据对象。 4. **配置选项** - `series`: 设置每种类型图表的样式,如线条样式、填充等。 - `xaxis` 和 `yaxis`: 自定义轴的范围、...
- **Flot**:作为jQuery的一个插件,Flot专门用于生成各种类型的图表,如折线图、柱状图、饼图等,支持时间序列数据和实时更新的数据流。 2. **特性** - **高效性能**:Flot利用HTML5的canvas元素进行绘图,提供...
jQuery Flot 是一个用于在网页上绘制高质量图形的开源库,它基于 jQuery,因此易于集成到任何使用 jQuery 的项目中。这个库提供了丰富的选项和插件,可以创建出各种各样的图表,包括折线图、柱状图、饼图等。在本文...
2. **性能优化**:Flot 使用 canvas 元素进行绘制,而非 SVG 或 VML,这在处理大量数据时能提供更好的性能。 3. **可扩展性**:Flot 提供了丰富的插件系统,可以添加诸如图例、工具提示、轴缩放等附加功能。 4. **...
在本实例中,我们将关注如何使用 `jQuery Flot` 实现实时更新的折线图。实时更新的数据通常在监控、数据分析或动态展示等场景中非常有用。 首先,我们需要了解 `jQuery Flot` 的基本用法。`Flot` 提供了一个简单的 ...
Flot支持绘制多种类型的图表,包括折线图、柱状图、饼图、面积图、散点图等,涵盖了数据可视化的主要需求。此外,还可以通过组合不同的图表类型,实现更复杂的可视化效果。 ### 6. 扩展性和社区支持 Flot拥有活跃...
jQuery曲线图和饼状图插件是数据可视化的重要工具,它们能够帮助开发者快速创建美观且互动的数据展示,尤其适用于网页应用中。 jQuery曲线图插件通常提供了丰富的功能,包括但不限于以下几点: 1. **动态数据更新*...
2. **丰富的图表类型**:Flot可以绘制折线图、面积图、柱状图、饼图等多种图表,满足各种数据可视化需求。 3. **实时更新**:Flot支持实时数据流,这意味着你可以动态地向图表添加新数据,使图表随时间变化而更新,...
**Flot资源详解** Flot是一个基于纯...通过这个提供的资源包,你可以深入学习Flot的使用,为你的报表设计增添新的元素和动态效果,提高数据的可读性和吸引力。记得尝试不同的配置和插件,发掘Flot更多的可能性。
5. **绘制图表**:使用jQuery选择器找到div元素,然后调用Flot的$.plot()方法,传入数据和配置选项,即可绘制出图表。 6. **交互处理**:可以通过绑定jQuery事件监听器来响应用户的交互行为,如点击图表、鼠标悬停...
6. **Updating and Redrawing**:Flot 图表可以动态更新,通过调用 `plot.setData` 和 `plot.setupGrid` 更新数据后,再调用 `plot.draw` 重新绘制图表,实现数据实时更新的效果。 7. **Axes**:Flot 支持自定义...
例如,如果你有一个JSON文件存储了需要绘制的数据,可以使用Ajax异步请求获取数据,然后解析JSON,将数据注入到图表中。这样,当数据发生变化时,图表会自动更新,实现动态效果。 ```javascript $.ajax({ url: '...
示例代码展示了如何使用jquery.flot.js绘制一个简单的折线图,它包含以下几个部分: 1. **HTML结构**:设置了基本的HTML页面结构,包括<!DOCTYPE html>、html标签、head标签以及用于展示图表的div容器。 2. **引入...