ExtJS 의 Chart 를 png / jpeg 로 내 보 내 중국어 난 장 판 해결

http://blog.sina.com.cn/s/blog_4ca83f800101ewn5.html
 
우 리 는 Chart 에서 chart 도 표를 그림 으로 내 보 낼 수 있 는 방법 이 있다 는 것 을 알 고 있다. 예 를 들 어: var chart=('Ext.chart.Chart',{...});chart.save({type: 'p_w_picpath/jpeg'});//jpeg 그림 으로 내 보 내 는 것 은 모든 영문 문자 데이터 에 대한 도표 입 니 다. 문제 가 없습니다.그러나 chart 에 중국어 문자 가 포함 되 어 있 으 면 내 보 낸 그림 에 오류 가 발생 하고 중국어 가 사각형 으로 표 시 됩 니 다 ( 네모 난 상 자 는 글꼴 설정 에 대응 하 는 인 코딩 이 없습니다. 물음표 입 니 다. 유 니 코드 - to - ANSI 는 지원 되 지 않 습 니 다. 물음표? 유 니 코드 를 코드 페이지 로 변환 하 는 데 실 패 했 기 때 문 입 니 다.)어 떡 하지?어 쩔 수 없 죠. 코드 를 추적 해 보 세 요. 다행히 EXTJS 문 서 는 괜 찮 네요.Ext. chart. Chart. save 의 원본 코드:
4. 567913. 관건 은 exporter 라 는 대상 인 것 같 습 니 다. 여기 서 ImageExporter 대상 이 분명 합 니 다. 그 속성 을 살 펴 보 니 defaultUrl 이 있 습 니 다."http://svg.sencha.io", save , , 、、 ??

chart , ??

,, 。。。 , : batik。 svg 。
spring mvc , controller svg :
@RequestMapping(value="/svg",method=RequestMethod.POST)
 private void svgServer(HttpServletRequest request,HttpServletResponse response) throws IOException{
 String svgString = request.getParameter("svg");

 String type = request.getParameter("type");
 response.setContentType(type);
 String filename = new Date().toLocaleString().replace(" ","_")+"."+type.substring(6);
 response.setHeader("Content-disposition","p_w_upload;filename=" + filename);

 JPEGTranscoder t = new JPEGTranscoder();
 t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,new Float(.8));
 TranscoderInput input = new TranscoderInput(new StringReader(svgString));
 try {
 TranscoderOutput output = new TranscoderOutput(response.getOutputStream());
 t.transcode(input, output);
 response.getOutputStream().flush();
 response.getOutputStream().close();
 }catch (Exception e){
 response.getOutputStream().close();
 e.printStackTrace();
 }
 }
Ext.chart.Chart.save :
var mySave = function(surface, config) {
 config = config || {};
 var exportTypes = {
 'p_w_picpath/png': 'Image',
 'p_w_picpath/jpeg': 'Image',
 'p_w_picpath/svg+xml': 'Svg'
 },
 prefix = exportTypes[config.type] || 'Svg',
 exporter = Ext.draw.engine[prefix + 'Exporter']; 
 exporter.defaultUrl = '';
 return exporter.generate(surface, config);
 };

 mySave(chart.surface,{
type: 'p_w_picpath/jpeg'
 });

좋은 웹페이지 즐겨찾기