mirror of
https://github.com/pyecharts/pyecharts.git
synced 2025-12-08 20:59:23 +00:00
Add: support table render
This commit is contained in:
parent
c7afa71bf3
commit
7daeab9c00
@ -1,16 +1,18 @@
|
||||
# coding=utf-8
|
||||
from pyecharts.components import Table
|
||||
|
||||
table = Table()
|
||||
|
||||
headers = ["City name", "Area", "Population", "Annual Rainfall"]
|
||||
rows = [
|
||||
["Brisbane", 5905, 1857594, 1146.4],
|
||||
["Adelaide", 1295, 1158259, 600.5],
|
||||
["Darwin", 112, 120900, 1714.7],
|
||||
["Hobart", 1357, 205556, 619.5],
|
||||
["Sydney", 2058, 4336374, 1214.8],
|
||||
["Melbourne", 1566, 3806092, 646.9],
|
||||
["Perth", 5386, 1554769, 869.4],
|
||||
]
|
||||
c = table.add(headers, rows)._repr_html_()
|
||||
print(c)
|
||||
def table_base():
|
||||
table = Table()
|
||||
|
||||
headers = ["City name", "Area", "Population", "Annual Rainfall"]
|
||||
rows = [
|
||||
["Brisbane", 5905, 1857594, 1146.4],
|
||||
["Adelaide", 1295, 1158259, 600.5],
|
||||
["Darwin", 112, 120900, 1714.7],
|
||||
["Hobart", 1357, 205556, 619.5],
|
||||
["Sydney", 2058, 4336374, 1214.8],
|
||||
["Melbourne", 1566, 3806092, 646.9],
|
||||
["Perth", 5386, 1554769, 869.4],
|
||||
]
|
||||
table.add(headers, rows)
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# coding=utf-8
|
||||
|
||||
from pyecharts import charts, commons, components, datasets, options, render, scaffold
|
||||
from pyecharts._version import __author__, __version__
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
|
||||
from jinja2 import Environment
|
||||
from prettytable import PrettyTable
|
||||
|
||||
from ..commons import utils
|
||||
from ..commons.types import List
|
||||
from ..commons.types import List, Optional
|
||||
from ..globals import CurrentConfig
|
||||
from ..render.display import HTML
|
||||
from ..render.engine import RenderEngine
|
||||
|
||||
|
||||
@ -15,20 +18,13 @@ class Table:
|
||||
):
|
||||
self.page_title = page_title
|
||||
self.js_host = js_host
|
||||
self.js_dependencies = utils.OrderedSet("bulma")
|
||||
self._charts = []
|
||||
|
||||
def add(self, headers: List, rows: List):
|
||||
table = PrettyTable(headers)
|
||||
for r in rows:
|
||||
table.add_row(r)
|
||||
self._charts.append(
|
||||
table.get_html_string(
|
||||
attributes={
|
||||
"class": "table is-bordered is-striped is-narrow is-hoverable is-fullwidth"
|
||||
}
|
||||
)
|
||||
)
|
||||
self._charts.append(table.get_html_string())
|
||||
return self
|
||||
|
||||
# List-Like Feature
|
||||
@ -39,5 +35,16 @@ class Table:
|
||||
def __len__(self):
|
||||
return len(self._charts)
|
||||
|
||||
def _repr_html_(self):
|
||||
return RenderEngine().render_chart_to_notebook("table.html", chart=self)
|
||||
def render(
|
||||
self,
|
||||
path: str = "render.html",
|
||||
template_name: str = "table.html",
|
||||
env: Optional[Environment] = None,
|
||||
) -> str:
|
||||
RenderEngine(env).render_chart_to_file(
|
||||
chart=self, path=path, template_name=template_name
|
||||
)
|
||||
return os.path.abspath(path)
|
||||
|
||||
def render_notebook(self):
|
||||
return HTML(RenderEngine().render_chart_to_notebook("table.html", chart=self))
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
jinja2>=2.8
|
||||
prettytable
|
||||
selenium
|
||||
|
||||
4
setup.py
4
setup.py
@ -12,11 +12,11 @@ from setuptools import Command, find_packages, setup
|
||||
|
||||
__title__ = "pyecharts"
|
||||
__description__ = "Python options, make charting easier"
|
||||
__url__ = "https://github.com/chenjiandongx/pyecharts"
|
||||
__url__ = "https://github.com/pyecharts/pyecharts"
|
||||
__author_email__ = "chenjiandongx@qq.com"
|
||||
__license__ = "MIT"
|
||||
|
||||
__requires__ = ["jinja2"]
|
||||
__requires__ = ["jinja2", "prettytable"]
|
||||
|
||||
__keywords__ = ["Echarts", "charts", "plotting-tool"]
|
||||
# Load the package's _version.py module as a dictionary.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user