Page 1 of 1

Transfer Cloud JSON to Jupyter Highcharts

Posted: Fri Jun 22, 2018 6:42 am
by marboh88
Hi there,

I created some charts in the Highcharts Cloud Editor and want to implement it now into my Jupyter notebook.

However, the transfer does not seem to work as expected. Anything I could do to make the chart render?

Code: Select all

from highcharts import Highstock

chart = Highstock()
chart.set_dict_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
I also tried:

Code: Select all

from highcharts import Highstock

chart = Highstock()
chart.set_dict_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

The error is:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-ef65b41151e9> in <module>()
54 "rules": []
55 },
---> 56 "legend": {}
57 })
58 chart

~/jupyter/ve/lib/python3.6/site-packages/highcharts/highstock/highstock.py in set_dict_options(self, options)
286 if isinstance(options, dict):
287 for key, option_data in options.items():
--> 288 self.set_options(key, option_data)
289 else:
290 raise OptionTypeError("Not An Accepted Input Format: %s. Must be Dictionary" %type(options))

~/jupyter/ve/lib/python3.6/site-packages/highcharts/highstock/highstock.py in set_options(self, option_type, option_dict, force_options)
277 self.setOptions[option_type].update_dict(**option_dict)
278 else:
--> 279 self.options[option_type].update_dict(**option_dict)
280
281

TypeError: update_dict() argument after ** must be a mapping, not list
Even if I get rid of legend:{} etc, it complains about the csv line which includes the data, with the same error.

Thanks in advance!

Re: Transfer Cloud JSON to Jupyter Highcharts

Posted: Fri Jun 22, 2018 10:00 am
by daniel_s
hi marboh88,

Welcome on Highcharts forum.
First, I think that question should be asked on Jupyter support instead of this forum. Could you try to implement some basic chart without complex configuration? (e.g {series: [{data: [1,2,3]}]})? Maybe could you provide me with the minimal working project implemented in Jupyter online enviroment? https://hub.mybinder.org/user/ipython-i ... #notebooks

Best regards!

Re: Transfer Cloud JSON to Jupyter Highcharts

Posted: Sun Jun 24, 2018 10:31 pm
by marboh88
Hi Daniel,

Thank you very much for your reply.
The link you posted seems not to work.

I tried a basic chart rendering and it works fine. The problem arises when I want to use the options dictionary from Highcharts Cloud. The code below is literally the only thing I have (besides the import and chart=Highchart() statements).


JSON:

Code: Select all

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)
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-cf584303e86e> in <module>()
1 options = {
----> 2 {"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":{}}
3 }
4
5 chart.set_dict_options(options)

TypeError: unhashable type: 'dict'




Options dictionary:

Code: Select all

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)
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-16-8e6d2634fb8a> in <module>()
54 }
55
---> 56 chart.set_dict_options(options)

~/jupyter/ve/lib/python3.6/site-packages/highcharts/highcharts/highcharts.py in set_dict_options(self, options)
302 if isinstance(options, dict):
303 for key, option_data in options.items():
--> 304 self.set_options(key, option_data)
305 else:
306 raise OptionTypeError("Not An Accepted Input Format: %s. Must be Dictionary" %type(options))

~/jupyter/ve/lib/python3.6/site-packages/highcharts/highcharts/highcharts.py in set_options(self, option_type, option_dict, force_options)
289 self.options[option_type].update_dict(**option_dict)
290 else:
--> 291 self.options[option_type].update_dict(**option_dict)
292
293 if option_type == 'chart' and 'options3d' in option_dict:

TypeError: update_dict() argument after ** must be a mapping, not list

Re: Transfer Cloud JSON to Jupyter Highcharts

Posted: Tue Jun 26, 2018 9:08 am
by daniel_s
hi marboh88,

My apologize for bad link. Here is the correct link: https://mybinder.org/v2/gh/ipython/ipyt ... ndex.ipynb, so please try to use it to build the simple demo. Are there some options changed by you in exported configuration?

Best regards!

Re: Transfer Cloud JSON to Jupyter Highcharts

Posted: Mon Feb 11, 2019 10:42 am
by aldrinjohn
marboh88 wrote: Sun Jun 24, 2018 10:31 pm
TypeError: unhashable type: 'dict'
[/quote]

The hash() is a built-in python method, used to return a unique number . This can be applied to any user-defined object which won’t get changed once initialized. This property is used mainly in dictionary keys .

TypeError: unhashable type: 'list' usually means that you are trying to use a list as an hash argument. For ex. when you use a list as a key in the dictionary , this cannot be done because lists can't be hashed. The standard way to solve this issue is to cast a list to a tuple .