Translator Part: Interfaces and Principles of pyecharts.javascripthon


From v0.6.0, pyecharts-javascripthon will merge into main code library, the original code will not be maintained.

pyecharts.javascripthon encapsulates the underlying Python-To-Javascript language translator.


pyecharts.javascripthon encapsulates a Python-To-Javascript language translator, defined in pyecharts.javascripthon.api module.


This class is the core class of the translator and contains a method translate. Interface is as follows

class EChartsTranslator:
    def translate(self, options: dict) -> JavascriptSnippet

JavascriptSnippet & FunctionSnippet

These two classes describe the data structure of the js code snippet. The interface is defined as follows:

class FunctionSnippet(OrderedDict):
    def to_js_snippet(self) -> six.text_type

class JavascriptSnippet:
    def __init__(self, function_snippet: FunctionSnippet, option_snippet: six.text_type):
    def to_js_snippet(self) -> six.text_type

The location of the code after each expansion is as follows:

var myChart_09de949b428d4e5db7782a12a7541e35 = echarts.init(document.getElementById('09de949b428d4e5db7782a12a7541e35'), null, {renderer: 'canvas'});

// FunctionSnippet starts
function on_click() {
function label_formatter(params) {
    return (params.value + " [Good!]");
// FunctionSnippet ends

var option_09de949b428d4e5db7782a12a7541e35 = {
  // omit
}; // options_snippet snippet

myChart_09de949b428d4e5db7782a12a7541e35.on("click", on_click);

Dummy objects

These APIs define the adaptation of some of Javascript's functions and objects, which are used only for declaration purposes.

Terms of usage

These functions or classes should be used by

For example, the following two introduction methods are all error.

Alias ​​introduce

from pyecharts.javascripthon.dom import Date as JDate

Module introduce

from pyecharts.javascripthon import dom

DOM object

Date, Math, JSON, window, Document, console, screen

from pyecharts.javascripthon.dom import window    # for window object
from pyecharts.javascripthon.dom import Document  # for Document object
from pyecharts.javascripthon.dom import Date      # for Date object
from pyecharts.javascripthon.dom import Math      # for Math module
from pyecharts.javascripthon.dom import JSON      # for JSON module
from pyecharts.javascripthon.dom import screen    # for screen object
from pyecharts.javascripthon.dom import console   # for console object

Global function

from pyecharts.javascripthon.dom import alert    # provide alert dialog to the user

Online translator API

Project url

pyecharts development team provides the project with an online conversion code function, which is actually to post the code to a server that supports the metapensiero.pj running environment, and could return the converted code.
pyecharts-javascripthon-api-service undertook this work. And the project has now been deployed on Heroku

If there are too many users, free resources will be exhausted. If you want to deploy to your own server, please refer to the documentation given by the project .