Display a chart using ECharts library. See echarts-java documentation for more info.
Method Signatures and Parameters | |
Jt.echarts(org.icepear.echarts.Chart<?, ?> chart) | chart (org.icepear.echarts.Chart<?, ?>) The ECharts |
Jt.echarts(org.icepear.echarts.Option chartOption) | chartOption (org.icepear.echarts.Option) The ECharts |
Jt.echarts(String chartOptionJson) | chartOptionJson (String) The ECharts option as a JSON string |
Chainable builder methods | |
height(int height) | The height of the chart in pixels. |
width(Integer width) | The width of the chart in pixels. If |
theme(io.jeamlit.components.chart.EchartsComponent.Theme theme) | The chart theme using a predefined theme from the Theme enum. |
theme(String theme) | The chart theme using a custom theme name. Custom themes can be loaded through custom headers. |
withMap(String mapName, java.net.URI geoJson) | A GEO map to register. You can register multiple maps by calling this method multiple times. The geoJson URI should point to valid geoJson file. If you want Jeamlit to host the file, see static file serving. |
withMap(String mapName, java.net.URI geoJson, Map<String, io.jeamlit.components.chart.EchartsComponent.SpecialAreaConfig> specialAreas) | A GEO map to register. You can register multiple maps by calling this method multiple times. The geoJson URI should point to valid geoJson file. If you want Jeamlit to host the file, see [static file serving](/get-started/fundamentals/additional-features#static-file-serving). |
border(boolean border) | Whether to show a border around the container. |
key(String key) | A string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key. |
No description | |
use() | Put the widget in the app, in the |
use(JtContainer container) | Put the widget in the app, in the provided container. |
Examples
Plot from a Chart
(Bar
extends Chart
).
import tech.catheu.jeamlit.core.Jt;
import org.icepear.echarts.Bar;
public class BarChartApp {
public static void main(String[] args) {
Bar bar = new Bar()
.setLegend()
.setTooltip("item")
.addXAxis(new String[] { "Matcha Latte", "Milk Tea", "Cheese Cocoa", "Walnut Brownie" })
.addYAxis()
.addSeries("2015", new Number[] { 43.3, 83.1, 86.4, 72.4 })
.addSeries("2016", new Number[] { 85.8, 73.4, 65.2, 53.9 })
.addSeries("2017", new Number[] { 93.7, 55.1, 82.5, 39.1 });
Jt.echarts(bar).use();
}
}
Plot from an Option
.
import tech.catheu.jeamlit.core.Jt;
import org.icepear.echarts.Option;
import org.icepear.echarts.charts.bar.BarSeries;
import org.icepear.echarts.components.coord.cartesian.CategoryAxis;
import org.icepear.echarts.components.coord.cartesian.ValueAxis;
import org.icepear.echarts.origin.util.SeriesOption;
public class OptionChartApp {
public static void main(String[] args) {
CategoryAxis xAxis = new CategoryAxis()
.setType("category")
.setData(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" });
ValueAxis yAxis = new ValueAxis().setType("value");
BarSeries series = new BarSeries()
.setData(new Number[] { 120, 200, 150, 80, 70, 110, 130 })
.setType("bar");
Option option = new Option()
.setXAxis(xAxis)
.setYAxis(yAxis)
.setSeries(new SeriesOption[] { series });
Jt.echarts(option).use();
}
}
Plot from a JSON String
import tech.catheu.jeamlit.core.Jt;
import org.icepear.echarts.Option;
import org.icepear.echarts.charts.bar.BarSeries;
import org.icepear.echarts.components.coord.cartesian.CategoryAxis;
import org.icepear.echarts.components.coord.cartesian.ValueAxis;
import org.icepear.echarts.origin.util.SeriesOption;
public class OptionChartApp {
public static void main(String[] args) {
String echartsOptionJson = """
{
"xAxis": {
"type": "category",
"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
},
"yAxis": {
"type": "value"
},
"series": [
{
"data": [150, 230, 224, 218, 135, 147, 260],
"type": "line"
}
]
}
""";
Jt.echarts(echartsOptionJson).use();
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.