Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa94e30

Browse files
incandescentxxcicepear-jzx
authored andcommitted
update default height and width for the charts & add apis to control height and width
1 parent95b2ba8 commitfa94e30

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

‎src/main/java/org/icepear/echarts/render/Engine.java‎

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void writeHtml(String html, String path, Boolean willOpen) {
4747

4848
/**
4949
* Used in simple chart case, render the echarts in html file, in default width,
50-
* height and willOpen
50+
* height and willOpen. The html file also provides download chart function.
5151
*
5252
* @param path path to save the html file
5353
* @param chart the chart to be rendered
@@ -85,20 +85,43 @@ public void render(String path, Option option) {
8585
}
8686
}
8787

88+
/**
89+
* Used in simple chart cases, render the echarts in
90+
* customized width, height, and willOpen
91+
*
92+
* @param path path to save the html file
93+
* @param option the option used to init the chart
94+
* @param height the height of the chart, ends with "px" or "%"
95+
* @param width the width of the chart, ends with "px" or "%"
96+
* @param willOpen whether allowing to open the html in browser automatically
97+
* @throws IOException
98+
*/
99+
publicvoidrender(Stringpath,Chart<?,?>chart,Stringheight,Stringwidth,BooleanwillOpen) {
100+
StringjsonStr =EChartsSerializer.toJson(chart.getOption());
101+
ChartMetachartMeta =newChartMeta(height,width,jsonStr);
102+
try {
103+
Templatetemplate =handlebars.compile("index");
104+
Stringhtml =template.apply(chartMeta);
105+
writeHtml(html,path,willOpen);
106+
}catch (IOExceptione) {
107+
log.info("render: Handlebars cannot find corresponding templates.");
108+
}
109+
}
110+
88111
/**
89112
* Used in both simple and advanced chart cases, render the echarts in
90113
* customized width, height, and willOpen
91114
*
92115
* @param path path to save the html file
93116
* @param option the option used to init the chart
94-
* @param height the height of the chart
95-
* @param width the width of the chart
117+
* @param height the height of the chart, ends with "px" or "%"
118+
* @param width the width of the chart, ends with "px" or "%"
96119
* @param willOpen whether allowing to open the html in browser automatically
97120
* @throws IOException
98121
*/
99-
publicvoidrender(Stringpath,Optionoption,intheight,intwidth,BooleanwillOpen) {
122+
publicvoidrender(Stringpath,Optionoption,Stringheight,Stringwidth,BooleanwillOpen) {
100123
StringjsonStr =EChartsSerializer.toJson(option);
101-
ChartMetachartMeta =newChartMeta("600px","600px",jsonStr);
124+
ChartMetachartMeta =newChartMeta(height,width,jsonStr);
102125
try {
103126
Templatetemplate =handlebars.compile("index");
104127
Stringhtml =template.apply(chartMeta);
@@ -118,7 +141,7 @@ public void render(String path, Option option, int height, int width, Boolean wi
118141
*/
119142
publicStringrenderHtml(Chart<?, ?>chart) {
120143
StringjsonStr =EChartsSerializer.toJson(chart.getOption());
121-
ChartMetachartMeta =newChartMeta("600px","100%",jsonStr);
144+
ChartMetachartMeta =newChartMeta("100%","100%",jsonStr);
122145
Templatetemplate =null;
123146
try {
124147
template =handlebars.compile("base");
@@ -139,7 +162,7 @@ public String renderHtml(Chart<?, ?> chart) {
139162
*/
140163
publicStringrenderHtml(Optionoption) {
141164
StringjsonStr =EChartsSerializer.toJson(option);
142-
ChartMetachartMeta =newChartMeta("600px","100%",jsonStr);
165+
ChartMetachartMeta =newChartMeta("100%","100%",jsonStr);
143166
Templatetemplate =null;
144167
try {
145168
template =handlebars.compile("base");
@@ -150,6 +173,28 @@ public String renderHtml(Option option) {
150173
}
151174
}
152175

176+
/**
177+
* Used in the simple cases, render the echarts in customized
178+
* width and height, without download button
179+
*
180+
* @param option the option to initiate the chart
181+
* @param height the height of the chart, ends with "px" or "%"
182+
* @param width the width of the chart, ends with "px" or "%"
183+
* @return the resulted string in html format
184+
* @throws IOException
185+
*/
186+
publicStringrenderHtml(Chart<?,?>chart ,Stringheight,Stringwidth)throwsIOException {
187+
StringjsonStr =EChartsSerializer.toJson(chart.getOption());
188+
ChartMetachartMeta =newChartMeta(height,width,jsonStr);
189+
try {
190+
Templatetemplate =handlebars.compile("base");
191+
returntemplate.apply(chartMeta);
192+
}catch (IOExceptione) {
193+
log.info("renderHtml: Handlebars cannot find corresponding templates.");
194+
return"";
195+
}
196+
}
197+
153198
/**
154199
* Used in both the simple and advanced cases, render the echarts in customized
155200
* width and height, without download button
@@ -160,9 +205,9 @@ public String renderHtml(Option option) {
160205
* @return the resulted string in html format
161206
* @throws IOException
162207
*/
163-
publicStringrenderHtml(Optionoption,intheight,intwidth)throwsIOException {
208+
publicStringrenderHtml(Optionoption,Stringheight,Stringwidth)throwsIOException {
164209
StringjsonStr =EChartsSerializer.toJson(option);
165-
ChartMetachartMeta =newChartMeta("600px","100%",jsonStr);
210+
ChartMetachartMeta =newChartMeta(height,width,jsonStr);
166211
try {
167212
Templatetemplate =handlebars.compile("base");
168213
returntemplate.apply(chartMeta);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp