score:0
they have a question like this on the high charts website
https://www.highcharts.com/forum/viewtopic.php?t=32634 which says
one option is to use getsvg - export image without any server: http://api.highcharts.com/highcharts#chart.getsvg second option would be to use highcharts default exporting server - post chart's options and get image: http://www.highcharts.com/docs/export-m ... e-overview third option is to set up your own exporting server:
http://www.highcharts.com/docs/export-m ... the-server
https://www.highcharts.com/blog/news/52-serverside-generated-charts/
main code segment:
function(chart) {
chart.renderer.arc(200, 150, 100, 50, -math.pi, 0).attr({
fill : '#fcffc5',
stroke : 'black',
'stroke-width' : 1
}).add();
}
and on stackoverflow:
how to save an image of the chart on the server with highcharts?
this shows a variety of methods and adapts the questions code to
var system = require('system');
var page = require('webpage').create();
var fs = require('fs');
// load js libraries
page.injectjs("js/jquery.min.js");
page.injectjs("js/highcharts/highcharts.js");
page.injectjs("js/highcharts/exporting.js");
// chart demo
var args = {
width: 600,
height: 500
};
var svg = page.evaluate(function(opt){
$('body').prepend('<div id="container"></div>');
var chart = new highcharts.chart({
chart: {
renderto: 'container',
width: opt.width,
height: opt.height
},
exporting: {
enabled: false
},
title: {
text: 'combination chart'
},
xaxis: {
categories: ['apples', 'oranges', 'pears', 'bananas', 'plums']
},
yaxis: {
title: {
text: 'y-values'
}
},
labels: {
items: [{
html: 'total fruit consumption',
style: {
left: '40px',
top: '8px',
color: 'black'
}
}]
},
plotoptions: {
line: {
datalabels: {
enabled: true
},
enablemousetracking: false
},
series: {
enablemousetracking: false,
shadow: false,
animation: false
}
},
series: [{
type: 'column',
name: 'andrii',
data: [3, 2, 1, 3, 4]
}, {
type: 'column',
name: 'fabian',
data: [2, 3, 5, 7, 6]
}, {
type: 'column',
name: 'joan',
data: [4, 3, 3, 9, 0]
}, {
type: 'spline',
name: 'average',
data: [3, 2.67, 3, 6.33, 3.33],
marker: {
linewidth: 2,
linecolor: 'white'
}
}, {
type: 'pie',
name: 'total consumption',
data: [{
name: 'andrii',
y: 13,
color: '#4572a7'
}, {
name: 'fabian',
y: 23,
color: '#aa4643'
}, {
name: 'joan',
y: 19,
color: '#89a54e'
}],
center: [100, 80],
size: 100,
showinlegend: false,
datalabels: {
enabled: false
}
}]
});
return chart.getsvg();
}, args);
// saving svg to a file
fs.write("demo.svg", svg);
// saving diagram as pdf
page.render('demo.pdf');
phantom.exit();
score:3
there are two ways of doing it. one as an image and the other as an interactive chart/hacky.
image. you will need to import requests
,image
and json
. the fig.options generated by justpy will be sent as a payload to the highcharts export server and will return an image.
import requests
from ipython.display import image
import json
#using the fig output from the justpy.plot extension
#fig = wm.jp.plot(0, ......
payload = {"async": true,
"constr": "chart",
"infile": fig.options,
"scale": false,
"type": "image/png",
"width": false}
response = requests.post("""https://export.highcharts.com/""" ,json=payload)
image(url='https://export.highcharts.com/'+response.text)
jupyter notebook interactive/hacky way of doing it for jupyter as interactive. i copied the approach here embedding d3.js
you will need to import 2 things and then use the %%javascript
cell magic. these are needed since the charts for highcharts need javascript to be rendered.
cell 1
#import needed
ipython.display import javascript
import json
cell 2
#using the fig output from the justpy.plot extension
#fig = wm.jp.plot(0, ......
#this converts the dict(addict is actually whats used by justpy) into json
javascript("""
window.dataforchart={};
""".format(json.dumps(fig.options)))
cell 3
this runs the javascript code that renders the chart and displays it in the notebook
%%javascript
require.config({
packages: [{
name: 'highcharts',
main: 'highcharts'
}],
paths: {
'highcharts': 'https://code.highcharts.com'
}
});
$("#chart1").remove();
element.append(`<div id="chart1"></div>`);
require([
'highcharts',
'highcharts/modules/exporting',
'highcharts/modules/accessibility'
], function (highcharts){highcharts.chart("chart1", window.dataforchart)});
jupyter lab interactive/hacky
cell 1
from ipython.display import javascript,html
import json
import requests
cell 2
#loads highcharts into the notebook. succeeding calls for
#highchart will work if you open this notebook.
response = requests.get('https://code.highcharts.com/highcharts.js')
javascript(response.text)
cell 3
javascript("""
window.dataforchart={};
""".format(json.dumps(fig.options)))
cell 4
#the html function has to be in the last line of the cell
#for this to work. also this become the output cell
html('<div id="chart123"></div>')
cell 5
#make sure that the chart id for the divs you make are unique so they
#dont overwrite each other
javascript('highcharts.chart("chart123", window.dataforchart);')
the image below is for the fruit chart example
Source: stackoverflow.com
Related Query
- Making a Highcharts plot with Python
- Add a gap between the second and third series in a Highcharts column plot with four series displayed
- Highcharts scatter plot with lots of data points running really slow
- Highcharts - multiple plot with the same x scale
- Highcharts scatter plot with variable line width
- Highcharts - Global configuration with common code and unique data & Headings
- HighCharts scatter plot with Datetime on X Axis not plotting values correctly
- Highcharts display grid over plot with z-index
- Tooltip in chart with line- and scatter plot in highcharts 3.0.7
- How to input plot data into highcharts with rails
- Highcharts - How to make a scatter plot with multiple series from HTML table
- how to use highcharts tooltip formatter in python code
- making title in highcharts clickable and work with bootstrap popover?
- passing formatting JavaScript code to HighCharts with JSON
- how to create highcharts formatted json structure with python
- Possible to use Highcharts Scatter Plot with categories?
- Plot Highcharts data from past 30 days with Ruby on Rails
- Highcharts for multiple plot lines each with a different color and show tooltip?
- Issue with Dates - trying to plot MongoDB data in Highcharts via PHP
- Box plot with Highcharts - TypeError: 'undefined' is not a constructor
- How to create two plot areas with highcharts
- Plot a bar graph using Highcharts drilldown with two different JSON end points
- Plot a a json chart with HighCharts & Vue.js
- Highcharts - Plot by week with and label formatter
- HighCharts - making a Pie with MySQL and PHP
- Error scraping Highcharts in Python with selenium
- Highcharts Vector Plot with connected vectors of absolute length
- Highcharts series visibility with csv data source
- rCharts and highcharts with shiny plot does not update correctly
- Fill area beneath scatter points with color in Highcharts 3d scatter plot
More Query from same tag
- Highcharts : using same div to load a chart multiple times with different series data
- Adding a comment box to a web page
- In Highchart, why drilldown data of pie chart is not of same color?
- I have no direct access to code but wonder if I can append my chart data points to a log file
- Highcharts add single line to column chart
- highcharts: TypeError: Cannot read property '0' of undefined
- My Highchart is stepping back to 01/18/1970 everytime. Why?
- ObHighchartsBundle: custom and set correctly xAxis with datetime and interval from DQL queries
- Highcharts stickyTracking
- Unable to load the series without duplication on highchart using angular 4
- Customize Highcharts xaxis label
- Highcharts multiple y axis and dynamic update
- convert Unix epoch timestamps to JavaScript date timestamps
- How to find the width of single cell in xaxis ? ( Refer screenshot )
- how to show one more array in the tooltip using highchart?
- Include export csv in highcharter
- Displaying labels near of each bar
- Chart highlighting in the highcharts javascript API
- Highcharts date in form of Day(Integer) - Month(the name of the month), like 17 - July
- Remove onhover effect from column chart
- R Highcharter customize legend to show only certain values
- Highcharts - Add more drill downs to large tree map
- Yii and ActiveRecord Group by Count
- HighMap - why the data doesn't display after clicking
- Minimise "Forced reflow"
- Is it possible to reparent the high charts legend?
- How do I create a break on the x-axis with highcharts?
- Highcharts: Generate chart from tables having linked data
- Using JSON data with the jQuery highcharts plugin
- Highcharts- Creating a dynamic x-axis to maintain bar spacing with less data points but maintain x-axis "width"