highcharts x轴不显示时间 求大神指教

guojia2012 2014-02-25 10:28:09
代码
   chart = {
// global: {
// useUTC: false
// },
chart: {
renderTo: 'container',
zoomType: 'x',
type: 'spline'


},
title: { text: '实时曲线图' },
credits:{text: ''},
xAxis: {
type: "datetime",
// tickInterval: 5*60 * 1000,
// tickWidth: 1000 * 60 * 30, //刻度的宽度
labels: {
enable: true,
rotation: 90, //旋转,效果就是影响标签的显示方向
//step: 4,
formatter: function () {
return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.value);
}
},
//刻度的宽度
lineColor: '#990000',
//自定义刻度颜色
lineWidth: 1,
//自定义x轴宽度
gridLineWidth: 1
//默认是0,即在图上没有纵轴间隔线
// dateTimeLabelFormats: { // don't display the dummy year
// second: '%H:%M:%S',
// minute: '%e. %b %H:%M',
// hour: '%b/%e %H:%M'
// }
},
yAxis:
{
title: {
text: '液位高度'
},
//刻度的宽度
lineColor: '#990000',
//自定义刻度颜色
lineWidth: 1,
//自定义x轴宽度
gridLineWidth: 1,
//默认是0,即在图上没有纵轴间隔线
alternateGridColor: null,
// plotLines: [{
// value: 0,
// width: 1,
// color: '#808080'
// }],
plotBands: [{ // Light air
from: 0,
to: 100,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Light breeze
from: 100,
to: 200,
color: 'rgba(0, 0, 0, 0)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Gentle breeze
from: 200,
to: 300,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Moderate breeze
from: 300,
to: 400,
color: 'rgba(0, 0, 0, 0)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Fresh breeze
from: 400,
to: 500,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Strong breeze
from: 500,
to: 600,
color: 'rgba(0, 0, 0, 0)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // High wind
from: 600,
to: 700,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}]
},
tooltip: {
enabled: true,
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' + unix_to_datetime(this.x) + '液位高度: ' + this.y + 'mm';
}
},
plotOptions:
{
spline:
{
lineWidth: 4,
states: {
hover:
{
lineWidth: 5
}
},
marker:
{
enabled: false
}
}
},
series:[{"name":"油箱1","data":[[1393251616,555.10],[1393251646,555.60],[1393251676,555.20],[1393251706,555.90],[1393251736,555.70],[1393251767,555.70],[1393251796,555.10],[1393251826,555.70],[1393251856,555.90],[1393251886,555.20],[1393251916,555.20],[1393251946,555.20],[1393251976,555.20],[1393252005,556.10],[1393252036,555.80],[1393252066,556.10],[1393252096,556],[1393252126,556.10],[1393252156,555.10],[1393252186,556.10],[1393252216,555.40],[1393252245,555.60],[1393252275,555.90],[1393252305,555.90],[1393252335,555.60]},{"name":"油箱2","data":[[1393251616,565.10],[1393251646,555.60],[1393251676,555.20],[1393251706,555.90],[1393251736,555.70],[1393251767,585.70],[1393251796,555.10],[1393251826,535.70],[1393251856,555.90],[1393251886,555.20],[1393251916,555.20],[1393251946,555.20],[1393251976,555.20],[1393252005,556.10],[1393252036,555.80],[1393252066,516.10],[1393252096,556],[1393252126,556.10],[1393252156,555.10],[1393252186,596.10],[1393252216,555.40],[1393252245,555.60],[1393252275,555.90],[1393252305,575.90],[1393252335,515.60]}]
};
//
// for (var i = 0; i < message.length; i++)
// {
// chart.series[i] = new Object();
// chart.series[i].name=message[i].name;
// chart.series[i].data=message[i].data;
// }
//chart.redraw();
option=new Highcharts.Chart(chart);

...全文
448 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liumingqiu32 2014-04-08
  • 打赏
  • 举报
回复
strValue +="'"+DateTi + "',"; 拼接时 单引号要加上 后台js 要加上“[]”
yyl8781697 2014-02-25
  • 打赏
  • 举报
回复
引用 2 楼 guojia2012 的回复:
数据是jax从后台取来的,json串没有问题
谁告诉你从ajax取来的数据 格式就没问题了? 如果仅仅从你帖子里面的series的值来看,就是因为data属性中少了一个"]"的闭合标签而导致格式无法识别 导致这种原因很有可能是你后台在拼接json字符串的时候少了闭合标签 还有我在本地测试unix_to_datetime这个函数是没有的,不知道LZ自己的代码里面有没有这个功能函数,如果没有的话 这个函数也是一个错误,会影响tooltip功能
Mirror然 2014-02-25
  • 打赏
  • 举报
回复
楼上这么远都看到了
guojia2012 2014-02-25
  • 打赏
  • 举报
回复
引用 1 楼 yyl8781697 的回复:
不知道LZ有没有对javascript进行调试,我发现是你series数据中少了"]"这个方括号 看现在得截图 再给你附上源码

<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

<script type="text/javascript">
$(function () {
       var chart = {
//               global: {
//                   useUTC: false
//               },
               chart: {
                   renderTo: 'container',
                   zoomType: 'x',
                   type: 'spline'


               },
               title: { text: '实时曲线图' },
               credits:{text: ''},
               xAxis: {
                   type: "datetime",
                // tickInterval: 5*60 * 1000,
//                   tickWidth: 1000 * 60 * 30, //刻度的宽度
                   labels: {
                       enable: true,
                       rotation: 90, //旋转,效果就是影响标签的显示方向
                       //step: 4,
                       formatter: function () {
                           return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.value);
                           }
                       },
                   //刻度的宽度
                   lineColor: '#990000',
                   //自定义刻度颜色
                   lineWidth: 1,
                   //自定义x轴宽度
                   gridLineWidth: 1
                   //默认是0,即在图上没有纵轴间隔线
//                    dateTimeLabelFormats: { // don't display the dummy year
//                      second: '%H:%M:%S',
//                    minute: '%e. %b %H:%M',
//                    hour: '%b/%e %H:%M'
//                        }
               },
               yAxis: 
               {
                   title: {
                       text: '液位高度'
                   },
                   //刻度的宽度
                   lineColor: '#990000',
                   //自定义刻度颜色
                   lineWidth: 1,
                   //自定义x轴宽度
                   gridLineWidth: 1,
                   //默认是0,即在图上没有纵轴间隔线
                   alternateGridColor: null,
//                   plotLines: [{
//                       value: 0,
//                       width: 1,
//                       color: '#808080'
//                   }],
                    plotBands: [{ // Light air
                    from: 0,
                    to: 100,
                    color: 'rgba(68, 170, 213, 0.1)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }, { // Light breeze
                    from: 100,
                    to: 200,
                    color: 'rgba(0, 0, 0, 0)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }, { // Gentle breeze
                    from: 200,
                    to: 300,
                    color: 'rgba(68, 170, 213, 0.1)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }, { // Moderate breeze
                    from: 300,
                    to: 400,
                    color: 'rgba(0, 0, 0, 0)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }, { // Fresh breeze
                    from: 400,
                    to: 500,
                    color: 'rgba(68, 170, 213, 0.1)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }, { // Strong breeze
                    from: 500,
                    to: 600,
                    color: 'rgba(0, 0, 0, 0)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }, { // High wind
                    from: 600,
                    to: 700,
                    color: 'rgba(68, 170, 213, 0.1)',
                    label: {
                        text: '',
                        style: {
                            color: '#606060'
                        }
                    }
                }]
               },
               tooltip: {
                   enabled: true,
                   formatter: function () {
                       return '<b>' + this.series.name + '</b><br/>' + this.x + '液位高度: ' + this.y + 'mm';
                   }
               },
                 plotOptions: 
                   {
                        spline: 
                        {
                           lineWidth: 4,
                           states: {
                               hover: 
                             {
                               lineWidth: 5
                             }
                          },
                        marker:
                            {
                            enabled: false
                            } 
                       }  
                      },
                   series:[{"name":"油箱1","data":[[1393251616,555.10],[1393251646,555.60],[1393251676,555.20],
				   [1393251706,555.90],[1393251736,555.70],[1393251767,555.70],[1393251796,555.10],[1393251826,555.70],
				   [1393251856,555.90],[1393251886,555.20],[1393251916,555.20],[1393251946,555.20],[1393251976,555.20],
				   [1393252005,556.10],[1393252036,555.80],[1393252066,556.10],[1393252096,556],[1393252126,556.10],
				   [1393252156,555.10],[1393252186,556.10],[1393252216,555.40],[1393252245,555.60],[1393252275,555.90],
				   [1393252305,555.90],[1393252335,555.60]]},
				   {"name":"油箱2","data":[[1393251616,565.10],[1393251646,555.60],[1393251676,555.20],
				   [1393251706,555.90],[1393251736,555.70],[1393251767,585.70],[1393251796,555.10],
				   [1393251826,535.70],[1393251856,555.90],[1393251886,555.20],[1393251916,555.20],
				   [1393251946,555.20],[1393251976,555.20],[1393252005,556.10],[1393252036,555.80],
				   [1393252066,516.10],[1393252096,556],[1393252126,556.10],[1393252156,555.10],
				   [1393252186,596.10],[1393252216,555.40],[1393252245,555.60],[1393252275,555.90],
				   [1393252305,575.90],[1393252335,515.60]]}]
           };
//      
//     for (var i = 0; i < message.length; i++)
//      {
//          chart.series[i] = new Object();
//          chart.series[i].name=message[i].name;
//          chart.series[i].data=message[i].data;
//      }
      //chart.redraw(); 
     // option=new Highcharts.Chart(chart);
    
        $('#container').highcharts(chart);
    });

</script>
</body>

</html>
数据是jax从后台取来的,json串没有问题
yyl8781697 2014-02-25
  • 打赏
  • 举报
回复
不知道LZ有没有对javascript进行调试,我发现是你series数据中少了"]"这个方括号
看现在得截图

再给你附上源码

<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

<script type="text/javascript">
$(function () {
var chart = {
// global: {
// useUTC: false
// },
chart: {
renderTo: 'container',
zoomType: 'x',
type: 'spline'


},
title: { text: '实时曲线图' },
credits:{text: ''},
xAxis: {
type: "datetime",
// tickInterval: 5*60 * 1000,
// tickWidth: 1000 * 60 * 30, //刻度的宽度
labels: {
enable: true,
rotation: 90, //旋转,效果就是影响标签的显示方向
//step: 4,
formatter: function () {
return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.value);
}
},
//刻度的宽度
lineColor: '#990000',
//自定义刻度颜色
lineWidth: 1,
//自定义x轴宽度
gridLineWidth: 1
//默认是0,即在图上没有纵轴间隔线
// dateTimeLabelFormats: { // don't display the dummy year
// second: '%H:%M:%S',
// minute: '%e. %b %H:%M',
// hour: '%b/%e %H:%M'
// }
},
yAxis:
{
title: {
text: '液位高度'
},
//刻度的宽度
lineColor: '#990000',
//自定义刻度颜色
lineWidth: 1,
//自定义x轴宽度
gridLineWidth: 1,
//默认是0,即在图上没有纵轴间隔线
alternateGridColor: null,
// plotLines: [{
// value: 0,
// width: 1,
// color: '#808080'
// }],
plotBands: [{ // Light air
from: 0,
to: 100,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Light breeze
from: 100,
to: 200,
color: 'rgba(0, 0, 0, 0)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Gentle breeze
from: 200,
to: 300,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Moderate breeze
from: 300,
to: 400,
color: 'rgba(0, 0, 0, 0)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Fresh breeze
from: 400,
to: 500,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // Strong breeze
from: 500,
to: 600,
color: 'rgba(0, 0, 0, 0)',
label: {
text: '',
style: {
color: '#606060'
}
}
}, { // High wind
from: 600,
to: 700,
color: 'rgba(68, 170, 213, 0.1)',
label: {
text: '',
style: {
color: '#606060'
}
}
}]
},
tooltip: {
enabled: true,
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' + this.x + '液位高度: ' + this.y + 'mm';
}
},
plotOptions:
{
spline:
{
lineWidth: 4,
states: {
hover:
{
lineWidth: 5
}
},
marker:
{
enabled: false
}
}
},
series:[{"name":"油箱1","data":[[1393251616,555.10],[1393251646,555.60],[1393251676,555.20],
[1393251706,555.90],[1393251736,555.70],[1393251767,555.70],[1393251796,555.10],[1393251826,555.70],
[1393251856,555.90],[1393251886,555.20],[1393251916,555.20],[1393251946,555.20],[1393251976,555.20],
[1393252005,556.10],[1393252036,555.80],[1393252066,556.10],[1393252096,556],[1393252126,556.10],
[1393252156,555.10],[1393252186,556.10],[1393252216,555.40],[1393252245,555.60],[1393252275,555.90],
[1393252305,555.90],[1393252335,555.60]]},
{"name":"油箱2","data":[[1393251616,565.10],[1393251646,555.60],[1393251676,555.20],
[1393251706,555.90],[1393251736,555.70],[1393251767,585.70],[1393251796,555.10],
[1393251826,535.70],[1393251856,555.90],[1393251886,555.20],[1393251916,555.20],
[1393251946,555.20],[1393251976,555.20],[1393252005,556.10],[1393252036,555.80],
[1393252066,516.10],[1393252096,556],[1393252126,556.10],[1393252156,555.10],
[1393252186,596.10],[1393252216,555.40],[1393252245,555.60],[1393252275,555.90],
[1393252305,575.90],[1393252335,515.60]]}]
};
//
// for (var i = 0; i < message.length; i++)
// {
// chart.series[i] = new Object();
// chart.series[i].name=message[i].name;
// chart.series[i].data=message[i].data;
// }
//chart.redraw();
// option=new Highcharts.Chart(chart);

$('#container').highcharts(chart);
});

</script>
</body>

</html>
yyl8781697 2014-02-25
  • 打赏
  • 举报
回复
引用 6 楼 guojia2012 的回复:
大师,你qq多少,详谈
我不是什么大师,我也没用过highcharts这个图表框架 我仅仅是根据你的javascript代码调试情况以及参考官方的Demo和api的基础上 对你的代码进行修改的
guojia2012 2014-02-25
  • 打赏
  • 举报
回复
引用 4 楼 yyl8781697 的回复:
[quote=引用 2 楼 guojia2012 的回复:] 数据是jax从后台取来的,json串没有问题
谁告诉你从ajax取来的数据 格式就没问题了? 如果仅仅从你帖子里面的series的值来看,就是因为data属性中少了一个"]"的闭合标签而导致格式无法识别 导致这种原因很有可能是你后台在拼接json字符串的时候少了闭合标签 还有我在本地测试unix_to_datetime这个函数是没有的,不知道LZ自己的代码里面有没有这个功能函数,如果没有的话 这个函数也是一个错误,会影响tooltip功能[/quote]大师,你qq多少,详谈
课程背景:    企业里面很多系统管理后台,用easyui + highcharts + django 进行后台管理的整合,而这块资料在网上资料甚少,很多有经验的朋友在做这块时候也经常出现各种问题,目前我们老师以前在大数据真实项目中用到这块,现在受一些网友建议单独录制easyui + highcharts + django,希望可以帮助那些同学。视频+技术文档+源码让你看过后马上也可以搭建起来。  比如现在的友盟 和 百度统计 都是在类似这样的统计,我们会通过2~3个小时左右的课程,让你掌握这样的技术。   目标人群:  1、初级以上普通开发人员  2、web开发人员,对python感兴趣同学  3、对编程感兴趣的同学   课程目录:  01easyui_highcharts_django整合之需介绍  02easyui_highcharts_django整合通过pycharm创建项目  03easyui_highcharts_django整合配置路由显示第一个页面  04easyui_highcharts_django整合下载easyui资源并且导入到项目里面  05easyui_highcharts_django整合修改配置文件加载static静态文件  06easyui_highcharts_django整合对页面进行修改  07easyui_highcharts_django整合对合并母模板layout  08easyui_highcharts_django整合添加一个新的业务的代码实现流程  09easyui_highcharts_django整合highcharts简单介绍  10easyui_highcharts_django整合highcharts的整合到django里面  11easyui_highcharts_django整合快速做出另一个业务流程  12easyui_highcharts_django整合柱状图  13easyui_highcharts_django后台返回json数据并且展示   14大数据django后台数据保存到mysql里面  15大数据django从mysql里面读取数据并显示到页面上面  课程环境:    环境:win10,  python 2.7.13,  django 1.8.3 ,  pymsql   收获预期:    1.使用django开发项目  2.学会使用easyui框架  3.学会使用highcharts  4.easyui_highcharts_django开发后面展示项目   案例截图:      

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧