Skip to contents

Takes a single highchartzero object or a named list of highchartzero objects and returns a JSON representation of the object(s).

Usage

chart_to_json(x)

Arguments

x

A single highchartzero object or a named list of highchartzero objects.

Value

A json object from jsonlite::toJSON().

Examples

data(example_charts)

chart_to_json(example_charts)
#> {"chart1":{"series":[{"data":[8,10,16],"type":"column","name":"mpg"}],"xAxis":{"categories":[4,6,8],"title":{"text":"cyl"}}},"chart2":{"series":[{"data":[4,5,8],"type":"column","name":"mpg"}],"xAxis":{"categories":[4,6,8],"title":{"text":"cyl"}}},"chart3":{"series":[{"name":3,"data":[{"cyl":4,"gear":3,"n":1,"x":4,"y":1},{"cyl":6,"gear":3,"n":2,"x":6,"y":2},{"cyl":8,"gear":3,"n":12,"x":8,"y":12}],"type":"column"},{"name":4,"data":[{"cyl":4,"gear":4,"n":8,"x":4,"y":8},{"cyl":6,"gear":4,"n":4,"x":6,"y":4}],"type":"column"},{"name":5,"data":[{"cyl":4,"gear":5,"n":2,"x":4,"y":2},{"cyl":6,"gear":5,"n":1,"x":6,"y":1},{"cyl":8,"gear":5,"n":2,"x":8,"y":2}],"type":"column"}],"plotOptions":{"column":{"stacking":"normal"}},"xAxis":{"categories":null,"title":{"text":"cyl"}},"legend":{"title":{"text":"gear"}}},"chart4":{"chart":{"reflow":true},"title":{"text":null},"yAxis":{"title":{"text":"MPG"},"type":"linear"},"credits":{"enabled":false},"boost":{"enabled":false},"plotOptions":{"series":{"label":{"enabled":false},"turboThreshold":0,"showInLegend":true},"treemap":{"layoutAlgorithm":"squarified"},"scatter":{"marker":{"symbol":"circle"}}},"series":[{"name":4,"data":[{"wt":2.32,"mpg":22.8,"cyl":4,"x":2.32,"y":22.8},{"wt":3.19,"mpg":24.4,"cyl":4,"x":3.19,"y":24.4},{"wt":3.15,"mpg":22.8,"cyl":4,"x":3.15,"y":22.8},{"wt":2.2,"mpg":32.4,"cyl":4,"x":2.2,"y":32.4},{"wt":1.615,"mpg":30.4,"cyl":4,"x":1.615,"y":30.4},{"wt":1.835,"mpg":33.9,"cyl":4,"x":1.835,"y":33.9},{"wt":2.465,"mpg":21.5,"cyl":4,"x":2.465,"y":21.5},{"wt":1.935,"mpg":27.3,"cyl":4,"x":1.935,"y":27.3},{"wt":2.14,"mpg":26,"cyl":4,"x":2.14,"y":26},{"wt":1.513,"mpg":30.4,"cyl":4,"x":1.513,"y":30.4},{"wt":2.78,"mpg":21.4,"cyl":4,"x":2.78,"y":21.4}],"type":"scatter"},{"name":6,"data":[{"wt":2.62,"mpg":21,"cyl":6,"x":2.62,"y":21},{"wt":2.875,"mpg":21,"cyl":6,"x":2.875,"y":21},{"wt":3.215,"mpg":21.4,"cyl":6,"x":3.215,"y":21.4},{"wt":3.46,"mpg":18.1,"cyl":6,"x":3.46,"y":18.1},{"wt":3.44,"mpg":19.2,"cyl":6,"x":3.44,"y":19.2},{"wt":3.44,"mpg":17.8,"cyl":6,"x":3.44,"y":17.8},{"wt":2.77,"mpg":19.7,"cyl":6,"x":2.77,"y":19.7}],"type":"scatter"},{"name":8,"data":[{"wt":3.44,"mpg":18.7,"cyl":8,"x":3.44,"y":18.7},{"wt":3.57,"mpg":14.3,"cyl":8,"x":3.57,"y":14.3},{"wt":4.07,"mpg":16.4,"cyl":8,"x":4.07,"y":16.4},{"wt":3.73,"mpg":17.3,"cyl":8,"x":3.73,"y":17.3},{"wt":3.78,"mpg":15.2,"cyl":8,"x":3.78,"y":15.2},{"wt":5.25,"mpg":10.4,"cyl":8,"x":5.25,"y":10.4},{"wt":5.424,"mpg":10.4,"cyl":8,"x":5.424,"y":10.4},{"wt":5.345,"mpg":14.7,"cyl":8,"x":5.345,"y":14.7},{"wt":3.52,"mpg":15.5,"cyl":8,"x":3.52,"y":15.5},{"wt":3.435,"mpg":15.2,"cyl":8,"x":3.435,"y":15.2},{"wt":3.84,"mpg":13.3,"cyl":8,"x":3.84,"y":13.3},{"wt":3.845,"mpg":19.2,"cyl":8,"x":3.845,"y":19.2},{"wt":3.17,"mpg":15.8,"cyl":8,"x":3.17,"y":15.8},{"wt":3.57,"mpg":15,"cyl":8,"x":3.57,"y":15}],"type":"scatter"}],"xAxis":{"type":"linear","title":{"text":"Weight"}},"legend":{"title":{"text":"Cylinders"}}}} 

chart_1 = example_charts[[1]]
chart_to_json(chart_1)
#> {"series":[{"data":[8,10,16],"type":"column","name":"mpg"}],"xAxis":{"categories":[4,6,8],"title":{"text":"cyl"}}}