Skip to content

The bionics service provides the ability to generate png images from JavaScript configurations and supports EChart charts

Generate EChart Image

Python Example

python
import requests
import base64

url = 'http://bionics.ops-pilot/echart/generate'

options = {
    "options": {
        "xAxis": {
            "type": "category",
            "boundaryGap": False,
            "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        },
        "yAxis": {
            "type": "value"
        },
        "series": [
            {
                "data": [820, 932, 901, 934, 1290, 1330, 1320],
                "type": "line",
                "areaStyle": {}
            }
        ]
    },
    "width": 500,
    "height": 200,
    "theme": "westeros",
    "fontSize": 12,
    "mode": "base64"
}

response = requests.post(url, json=options)


if response.status_code == 200:
    
    image_data_base64 = response.text.replace("data:image/png;base64,", "")

    image_data = base64.b64decode(image_data_base64)

    with open("generated_chart.png", "wb") as image_file:
        image_file.write(image_data)

    print("Image successfully saved to 'generated_chart.png'")
else:
    print(f"Failed to generate image. Status code: {response.status_code}")
    print(f"Response: {response.text}")

Rest API

bash
curl --location --request POST --X POST 'http://bionics.ops-pilot/echart/generate' \
--header 'Content-Type: application/json' \
--data '{
	"options":{
      "xAxis": {
        "type": "category",
        "boundaryGap": false,
        "data": [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ]
      },
      "yAxis": {
        "type": "value"
      },
      "series": [
        {
          "data": [ 820, 932, 901, 934, 1290, 1330, 1320 ],
          "type": "line",
          "areaStyle": {}
        }
      ]
    }
}'
ParameterDescriptionMandatoryDefault valueRemarks
The optionsEchart chart Optionsis
widthCanvas widthNo500speed at which the Canvas size will be generated
heightCanvas heightno200Canvas size speed at which the canvas will be generated
themeEchart's themenowesteros
fontSizeCanvas font sizeno12
modeThe returned image format isnobase64The optional base64/stream. In Base64 mode, the image is encoded as Base64 and returned to the caller; in Stream mode, the image is returned directly in stream mode