使用highchart无数据时的样式
来源:互联网 发布:spring mvc初始化数据 编辑:程序博客网 时间:2024/05/16 11:35
url:http://blog.csdn.net/zk437092645/article/details/12065125
当使用highchart图表插件时,如果服务器返回的数据为空,那么在页面上就会显示一大块没有内容的空白,显得很难看,因此需要寻找解决方案,起码也得显示一条无数据的提示吧?
方法一:
返回数据为空时,直接return,不去执行highcharts方法,然后在相应位置添加提示。
方法二:
在highchart图表内部显示无数据的提示文字
方法二在GOOGLE上找到了答案。
- <script src="http://code.highcharts.com/highcharts.js"></script>
- <script src="http://github.highcharts.com/master/modules/no-data-to-display.src.js"></script>
- <script src="http://code.highcharts.com/modules/exporting.js"></script>
- <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
- <button id="add">Add data</button>
- <button id="remove">Remove data</button>
- <button id="showCustom">Show custom message manually</button>
- /*
- Demonstrate no-data-to-display plugin.
- The plugin will automatically display a customizable message when there is no data visible in the chart.
- It can alternatively be displayed/hidden at any time manually, optionally with custom text. There is also
- a new function "hasData()" for charts and series, returning true if there is data visible in the plot area.
- */
- $(function () {
- var chart,
- btnRemove = $('#remove'),
- btnAdd = $('#add'),
- btnShow = $('#showCustom');
- btnAdd.click(function () {
- chart.series[0].addPoint(Math.floor(Math.random() * 10 + 1));
- });
- btnRemove.click(function () {
- if(chart.series[0].points[0]) {
- chart.series[0].points[0].remove();
- }
- });
- // Show a custom message
- btnShow.click(function () {
- if(!chart.hasData()) { // Only if there is no data
- chart.hideNoData(); // Hide old message
- chart.showNoData("Your custom error message");
- }
- });
- $('#container').highcharts({
- title: {
- text: 'No data in line chart - with custom options'
- },
- series: [{
- type: 'line',
- name: 'Random data',
- data: []
- }],
- lang: {
- // Custom language option
- //noData: "Nichts zu anzeigen"
- },
- /* Custom options */
- noData: {
- // Custom positioning/aligning options
- position: {
- //align: 'right',
- //verticalAlign: 'bottom'
- },
- // Custom svg attributes
- attr: {
- //'stroke-width': 1,
- //stroke: '#cccccc'
- },
- // Custom css
- style: {
- //fontWeight: 'bold',
- //fontSize: '15px',
- //color: '#202030'
- }
- }
- });
- chart = $('#container').highcharts();
- });
显示效果如图所示:
文章代码引自 http://jsfiddle.net/highcharts/hxGmq/
0 0
- 使用highchart无数据时的样式
- 使用highchart无数据时的样式
- 使用HighChart的一些心得
- jQuery easy ui datagrid 无数据时的样式
- highchart使用
- highchart的数据加载以及实时刷新
- HighChart 动态加载数据 不成功的解决办法
- highchart 的折线图 的使用
- 关于使用highchart控件的心得。。
- 使用AngularJS结合Highchart图表动态获取JSON格式数据
- jqgrid无数据样式呈现
- HighCharts自定义"无数据样式"
- highchart 动态添加数据
- 关于jqgrid生成表单无数据时的显示。它本身的样式是会在右下角显示无数据显示,能不能让它和qq邮箱一样
- HighChart使用总结
- ExtJs中使用highChart
- 使用highchart.js
- vue中使用highchart
- iOS开发--多线程编程(二)NSThread买票
- jetty上手
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_4_中点椭圆算法(上)
- JavaScript 进阶学习 2 数组
- c++第四次作业
- 使用highchart无数据时的样式
- Android中关于保留小数点位数的处理
- openGL 超级宝典第五版 vs环境配置
- 布局时负值的妙用
- Jenkins -- Linux slave配置
- android:ellipsize="end" + android:maxLines="" 失败的原因与解决方案
- 剑指offer(26):二叉树中和为某一值的路径
- 《第一行代码》学习笔记之网络技术
- POJ 3468 A Simple Problem with Integers