如果您对ajax–在时间序列ZingChart中,在实时使用appendseriesvalues时,xValue导致问题感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解ajax–在时间序列Zin
如果您对ajax – 在时间序列ZingChart中,在实时使用appendseriesvalues时,xValue导致问题感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解ajax – 在时间序列ZingChart中,在实时使用appendseriesvalues时,xValue导致问题的各种细节,此外还有关于''dict_values'' object does not support indexing, Python字典dict中由value查key、081:QuerySet API详解-values和values_list、@Value("#{configProperties[''requestUrl'']}")和 @Value("${bbbb}") 这两种配置形式有什么区别?、An invalid character [32] was present in the Cookie value 错误的实用技巧。
本文目录一览:- ajax – 在时间序列ZingChart中,在实时使用appendseriesvalues时,xValue导致问题
- ''dict_values'' object does not support indexing, Python字典dict中由value查key
- 081:QuerySet API详解-values和values_list
- @Value("#{configProperties[''requestUrl'']}")和 @Value("${bbbb}") 这两种配置形式有什么区别?
- An invalid character [32] was present in the Cookie value 错误
ajax – 在时间序列ZingChart中,在实时使用appendseriesvalues时,xValue导致问题
我的代码如下:
var chartData = { "show-progress":false,"gui":{ "behaviors":[ { "id":"ZoomIn","enabled":"all" },{ "id":"ZoomOut",{ "id":"ShowAll","enabled":"all" } ] },"type":"line",// "utc":true,/* Force UTC time. */ // "timezone": -5,"plotarea": { "adjust-layout":true /* For automatic margin adjustment. */ },"scale-x":{ "values": [],"label":{ /* Add a scale title with a label object. */ "text":"Above is an example of a time-series scale",},"min-value":1420070400000,/* Unix timestamp for Jan 1,2015. */ "step":"second","transform":{ /* Converts your Unix timestamp to a human readable format. */ "type":"date",/* Set your transform type to "date". */ "all":"%h:%i:%s" /* Specify your date/time format,using tokens. */ },"line-color":"none","tick":{ "visible":false },"zooming":1,"item":{ "font-color":"#000","visible":true },// "max-labels":10000,"itemsOverlap": true },"scale-y":{ "zooming":1,"items-overlap": true },"series":[ { "values":[] } ],}; window.onload = function() { zingchart.render({ id: "chartDiv",data: chartData,height: 600,width: "100%" }); }; setInterval(flashText,1000); function flashText() { $.ajax({ type: "POST",dataType: "json",headers: { Accept: "application/json","Access-Control-Allow-Origin": "*" },url: "TestServlet2",success:function(data) { $.each(data,function(key,value) { zingchart.exec('chartDiv','appendseriesvalues',{ values: [[key,value]],}) }); },}); }
如果我使用此代码创建,它将键和值作为2个串联值.我想将其绘制为(键,值).请建议我做错了什么.提前致谢!
如果您还没有看到它,我们的网站上有一个realtime feed部分.为了保留您的问题主题,我将向您展示如何将API调用合并到ZingChart中.
我要做的第一个假设是密钥是时间戳号,以毫秒为单位,值是数字类型.我假设key是一个时间戳,因为你定义了转换对象并将min值设置为时间戳.
"min-value":1420070400000,2015. */
如果不是这样,请说明,但我将继续这个例子.假设您输入的数据是正确的,您唯一没有做的就是指定绘图索引.根据我们的appendseriesvalues文档,如果仅更新单个图,则必须定义plotindex.我已经使用了大部分配置来创建一个图表,该图表使用API方法appendseriesvalues每秒绘制一个[timestamp,value]对.
var chartData = { "show-progress":false,"gui":{ "behaviors":[ { "id":"ZoomIn","enabled":"all" },{ "id":"ZoomOut",{ "id":"ShowAll","enabled":"all" } ] },/* Force UTC time. */ // "timezone": -5,"plotarea": { "adjust-layout":true,/* For automatic margin adjustment. */ "margin-right":50 },"scale-x":{ "values": [],"label":{ /* Add a scale title with a label object. */ "text":"Above is an example of a time-series scale",2015. */ "step":"second","transform":{ /* Converts your Unix timestamp to a human readable format. */ "type":"date",/* Set your transform type to "date". */ "all":"%h:%i:%s" /* Specify your date/time format,using tokens. */ },"tick":{ "visible":false },"item":{ "font-color":"#000","visible":true },"itemsOverlap": true },"scale-y":{ "zooming":1,"items-overlap": true },"series":[ { "values":[] } ] }; window.onload = function() { zingchart.render({ id: "myChart",height: 400,width: "100%" }); }; // variable for incrementing time var increment = 0; // Every second add a new datapoint setInterval(function() { var data = []; for (var i = 0; i < 1000; i++) { data.push(Math.random() * 25 + i); } zingchart.exec('myChart',{ plotindex:0,// The index of the plot if only appending the data on a single plot. values: [[1420070400000 + increment,data]] }); increment += 100; },1000);
<!DOCTYPE html> <html> <head> <script src= "https://cdn.zingchart.com/zingchart.min.js"></script> </head> <body> <div id='myChart'></div> </body> </html>
''dict_values'' object does not support indexing, Python字典dict中由value查key
Python字典dict中由value查key
众所周知,字典dict最大的好处就是查找或插入的速度极快,并且不想列表list一样,随着key的增加越来越复杂。但是dict需要占用较大的内存空间,换句话说,字典dict是以空间换速度。详细请见如下示例:
#------------------------------------------------------------------------------------
student = {''小萌'': ''1001'', ''小智'': ''1002'', ''小强'': ''1003'', ''小明'': ''1004''}
#------------------------------------------------------------------------------------
由key查value很简单,直接调用:dict [''key''],如下:
#-----------------------------------------------------------------------------------
>>> student [''小强'']
结果显示:''1003''
#-----------------------------------------------------------------------------------
但如果此时,我们想由value查找key,则会相对复杂一点,一般来说可通过如下3种方式实现:
#-----------------------------------------------------------------------------------
A. 充分利用 keys() 、values()、index() 函数
>>> list (student.keys()) [list (student.values()).index (''1004'')]
结果显示: ''小明''
#-----------------------------------------------------------------------------------
B. 通过定义get_key函数的方式
>>> def get_key (dict, value):
return [k for k, v in dict.items() if v == value]
>>> get_key (student, ''1002'')
结果显示:''小智''
#-----------------------------------------------------------------------------------
C. 将原字典dict进行反转得新字典new_dict,由原来的K-V存储形式,变为V-K存储形式
>>> new_dict = {v : k for k, v in dict.items()}
>>> new_dict [''1001'']
结果显示:''小萌''
#-----------------------------------------------------------------------------------
虽然我们可以通过以上方式获得由value查找key的目的,但是我们必须明确一点:在字典dict中,key值是唯一的,且不可变;而value可以随意取值,且不唯一。之所以强调这一点,是因为在利用上述方法时,会出现失效的情况。如下所示:
假设此时原字典student发生了一些变化,变为:
#-----------------------------------------------------------------------------------
student = {''小萌'': ''1001'', ''小智'': ''1002'', ''小强'': ''1003'', ''小明'': [''1004'', ''1005'']}
#-----------------------------------------------------------------------------------
那么再次调用上述3种方法,由value查key时,则出现:
#-----------------------------------------------------------------------------------
>>> list (student.keys()) [list (student.values()).index (''1004'')]
结果显示:ValueError: ''1004'' is not in list
因为value不唯一,key—''小明'' 对应了两个value,且他们以list形式存储着,所以如果只取其中一个value值是无法查找对应的key值,必须将多个value值组成的list视为一个整体,即:
>>> list (student.keys()) [list (student.values()).index ([''1004'', ''1005''])]
结果显示:''小明''
#-----------------------------------------------------------------------------------
>>> def get_key (dict, value):
return [k for k, v in dict.items() if v == value]
>>> get_key (student, ''1004'')
结果显示:[ ]
>>> get_key (student, [''1004'', ''1005''])
结果显示:''小明''
#-----------------------------------------------------------------------------------
>>> new_dict = {v : k for k, v in dict.items()}
回车后系统报错:TypeError: unhashable type: ''list''
由于key不可变且唯一,当K-V反转以后,key—''小明'' 对应了两个value组成的list,反过来就变成了key,即此时由list充当key,因为list是可变动的,所以这在Python中是不允许的。python中dict根据value找到keyname
''dict_values'' object does not support indexing
In Python 3, dict.values()
(along with dict.keys()
and dict.items()
) returns a view
, rather than a list. See the documentation here. You therefore need to wrap your call to dict.values()
in a call to list
like so:
v = list(d.values()) {names[i]:v[i] for i in range(len(names))}
The immediate answer is that a dict''s values
method returns a non-indexable object, as the error indicates. You can get around that by passing to to list:
list(word_centroid_map.values())
But really you''d do better to rewrite your loop like this:
for key, value word_centroid_map.items():
if value == cluster:
words.append(key)
Or even better, use a list comprehension:
words = [k for k, v in word_centroid_map.items() if v == cluster]
081:QuerySet API详解-values和values_list
QuerySet API详解-values和values_list:
values
:用来指定在提取数据出来,需要提取哪些字段。默认情况下会把表中所有的字段全部都提取出来,可以使用values
来进行指定,并且使用了values
方法后,提取出的QuerySet
中的数据类型不是模型,而是在values
方法中指定的字段和值形成的字典:
# books = Book.objects.values("id", "name", "price")
# books = Book.objects.values("id", "name", author_name=F("author__name"))
books = Book.objects.values("id", "name", sum=Count("bookorder__id"))
print(books)
for item in books:
print(item)
以上打印出来的article
是类似于{"title":"abc","content":"xxx"}
的形式。如果在values
中没有传递任何参数,那么将会返回这个恶模型中所有的属性。
values_list
:类似于values
。只不过返回的QuerySet
中,存储的不是字典,而是元组。示例代码如下:
# books = Book.objects.values_list()
books = Book.objects.values_list("id", "name")
print(books)
for item in books:
print(item)
那么在打印articles
后,结果为<QuerySet [(1,''abc''),(2,''xxx''),...]>
等。如果在values_list
中只有一个字段。那么你可以传递flat=True
来将结果扁平化。示例代码如下:
books = Book.objects.values_list("name", flat=True)
工程实例截图:
@Value("#{configProperties[''requestUrl'']}")和 @Value("${bbbb}") 这两种配置形式有什么区别?
@Value("#{configProperties[''requestUrl'']}")和 @Value("${bbbb}") 这两种配置形式有什么区别?一直用的第二种这种,第一种这种带中括号的啥意思?
An invalid character [32] was present in the Cookie value 错误
今天在做 cookie 部分的 demo 的时候出现了一个错误 Servlet 部分的代码如下
1 Date data=new Date();
2 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
3 String Last = format.format(data);
4 // System.out.println(Last);
5
6
7 Cookie cookie =new Cookie("Lastname",Last);
8 cookie.setMaxAge(60*10*500);
9 response.addCookie(cookie);
10 //获得用户携带的cookie
11 String last=null;
12 Cookie[] cookies = request.getCookies();
13 if(cookies!=null){
14 for(Cookie coo:cookies){
15 if("Lastname".equals(coo.getName())){
16 last = coo.getValue();
17
18 }
19 }
20 }
21
22 response.setContentType("text/html;charset=utf-8");
23 if(last==null){
24
25 response.getWriter().write("您是第一次访问");
26 }else{
27 response.getWriter().write("你上次访问的时间为"+last);
28 }
再访问该 Servlet 的时候页面就为 500,并报异常 An invalid character [32] was present in the Cookie value,
后来发现 32 对应的编码是空格,后来发现
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");代码中产生了空格,后改为
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss");就可正常访问了

关于ajax – 在时间序列ZingChart中,在实时使用appendseriesvalues时,xValue导致问题的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于''dict_values'' object does not support indexing, Python字典dict中由value查key、081:QuerySet API详解-values和values_list、@Value("#{configProperties[''requestUrl'']}")和 @Value("${bbbb}") 这两种配置形式有什么区别?、An invalid character [32] was present in the Cookie value 错误等相关知识的信息别忘了在本站进行查找喔。
本文标签: