gpt4 book ai didi

java - Highchart Java 导出图像

转载 作者:太空宇宙 更新时间:2023-11-04 06:25:04 26 4
gpt4 key购买 nike

我正在尝试使用 highchart 导出服务器生成图表图像。此代码返回文本/html 而不是图像。不确定这里出了什么问题。

package com.vidyartha;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;

public class CreateChart {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

HttpPost post = new HttpPost("http://export.highcharts.com");


HttpClient client = HttpClientBuilder.create().build();

try{

String str="{'xAxis': {'categories': ['Jan', 'Feb', 'Mar']},'series': [{'data': [29.9, 71.5, 106.4]}]};";
String dataString = "{type:image/png,options:" + str+"}";
post.setEntity(new StringEntity(dataString,
ContentType.create("application/json")));

HttpResponse response = client.execute(post);

InputStream is = response.getEntity().getContent();


String filePath = "E:\\pdf\\rakesh.png";
FileOutputStream fos = new FileOutputStream(new File(filePath));

int inByte;
while((inByte = is.read()) != -1) fos.write(inByte);
is.close();
fos.close();

System.out.println("Got Repsonse");
System.out.println(response);


}catch(Exception e){
System.out.println(e);
}



}
}

最佳答案

您没有发送正确的parameters 。您需要使用以下表单数据构建 POST 请求:

options = {'xAxis': {'categories': ['Jan', 'Feb', 'Mar']},'series': [{'data': [29.9, 71.5, 106.4]}]}
type = image/png
constr = Chart

我在PostMan中尝试过这个而且效果很好。

关于java - Highchart Java 导出图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26893744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com