在Jupyter笔记本电脑中使用Highcharts Cloud JSON

时间:2018-06-24 22:38:52

标签: json highcharts jupyter-notebook jupyter

我在Highcharts Cloud Editor中创建了一些图表,现在想在Jupyter笔记本中实现它。

但是,传输似乎没有按预期进行。我可以做些什么来使图表呈现出来?

我可以从Highcharts Cloud中导出几种方式,我尝试了options数组以及JSON脚本:

JSON:

options = {
{"chart":{"type":"column","inverted":True,"polar":False},"plotOptions":{"series":{"stacking":"normal","dataLabels":{"enabled":True},"animation":False}},"title":{"text":"Commitment of Traders Net Positions"},"subtitle":{"text":"Options only"},"series":[{"name":"Net Hedging","turboThreshold":0,"_colorIndex":0,"marker":{"enabled":False},"colorByPoint":False},{"name":"Net Speculation","turboThreshold":0,"_colorIndex":1}],"yAxis":{"title":{"text":"Net open interest ('000)"}},"xAxis":{},"data":{"csv":"\"Commodity\";\"Net Hedging\";\"Net Speculation\"\n\"Crude oil\";-2.66;66.58\n\"Natural gas\";-6.28;6.4\n\"Gold\";-28.33;31.48\n\"Silver\";-8.6;7.16\n\"Corn\";-18.79;-27.98\n\"Soybeans\";-5.04;6.93"},"pane":{"background":[]},"responsive":{"rules":[]},"legend":{}}
}

chart.set_dict_options(options)

错误消息:

  

-------------------------------------------------- ---------------------------- TypeError追踪(最近一次通话)    in()1个选项= {   ----> 2 {“ chart”:{“ type”:“ column”,“ inverted”:True,“ polar”:False},“ plotOptions”:{“ series”:{“ stacking”:“ normal” ,“ dataLabels”:{“ enabled”:True},“ animation”:False}},“ title”:{“ text”:“承诺   交易员净头寸”},“字幕”:{“文本”:“期权   only“},” series“:[{” name“:” Net   对冲“,” turboThreshold“:0,” _ colorIndex“:0,”标记“:{” enabled“:False},” colorByPoint“:False},{” name“:” Net   Speculation“,” turboThreshold“:0,” _ colorIndex“:1}],” yAxis“:{” title“:{” text“:” Net   未平仓合约('000)“}},” xAxis“:{},” data“:{” csv“:” \“商品\”; \“净额   对冲\“; \”净投机\“ \ n \”原油“; -2.66; 66.58 \ n \”自然   gas \“;-6.28; 6.4 \ n \” Gold \“;-28.33; 31.48 \ n \” Silver \“;-8.6; 7.16 \ n \” Corn \“;-18.79; -27.98 \ n \”大豆\“;-5.04; 6.93”},“窗格”:{“背景”:[]},“响应”:{“规则”:[]},“传奇”:{}} 3} 4 5 chart.set_dict_options (选项)

     

TypeError:不可散列的类型:'dict'

或从Highcharts云中放入选项字典:

options = {
    "chart": {
    "type": "column",
    "inverted": True,
    "polar": False
  },
  "plotOptions": {
    "series": {
      "stacking": "normal",
      "dataLabels": {
        "enabled": True
      },
      "animation": False
    }
  },
  "title": {
    "text": "Commitment of Traders Net Positions"
  },
  "subtitle": {
    "text": "Options only"
  },
  "series": [
    {
      "name": "Net Hedging",
      "turboThreshold": 0,
      "_colorIndex": 0,
      "marker": {
        "enabled": False
      },
      "colorByPoint": False
    },
    {
      "name": "Net Speculation",
      "turboThreshold": 0,
      "_colorIndex": 1
    }
  ],
  "yAxis": {
    "title": {
      "text": "Net open interest ('000)"
    }
  },
  "xAxis": {},
  "data": {
    "csv": "\"Commodity\";\"Net Hedging\";\"Net Speculation\"\n\"Crude oil\";-2.66;66.58\n\"Natural gas\";-6.28;6.4\n\"Gold\";-28.33;31.48\n\"Silver\";-8.6;7.16\n\"Corn\";-18.79;-27.98\n\"Soybeans\";-5.04;6.93",
  },
  "pane": {
    "background": []
  },
  "responsive": {
    "rules": []
  },
  "legend": {}
}

chart.set_dict_options(options)

这给了我以下错误:

  

-------------------------------------------------- ---------------------------- TypeError追踪(最近一次通话)    在()54} 55   ---> 56 chart.set_dict_options(options)

     

〜/ jupyter / ve / lib / python3.6 / site-packages / highcharts / highcharts / highcharts.py   在set_dict_options(self,options)302中,如果isinstance(options,dict):   303,用于options.items()中的option_data密钥:   -> 304 self.set_options(key,option_data)305否则:306引发OptionTypeError(“不可接受的输入格式:%s。必须为字典”   %type(options))

     

〜/ jupyter / ve / lib / python3.6 / site-packages / highcharts / highcharts / highcharts.py   在set_options(self,option_type,option_dict,force_options)中289   self.options [option_type] .update_dict(** option_dict)290其他:   -> 291 self.options [选项类型] .update_dict(** option_dict)292293如果option_dict中的option_type =='chart'和'options3d':

     

TypeError:**之后的update_dict()参数必须是映射,而不是列表

必须有一种方法可以将Highcharts Cloud图表渲染到我的Jupyter笔记本中?任何帮助都不胜感激:)

0 个答案:

没有答案