2011-01-10 70 views
0

这是它提供了如下结果我的示例应用程序:Java来JSON格式

Array Values : 
arr[0][0] :6 
arr[0][1] :0 
arr[0][2] :0 
arr[1][0] :0 
arr[1][1] :0  
arr[1][2] :0 

因为我有这样的jQuery Highcharts:

chart = new Highcharts.Chart({ 
           chart: { 
           renderTo: 'container', 
           defaultSeriesType: 'column' 
           }, 
           title: { 
         text: document.chart.chartTitle.value 
           },            
           series: [{ 
           name: 'USA', 
           data: [50, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] 
           }, { 
           name: 'New York', 
           data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3] 
           }, { 
           name: 'London', 
           data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2] 
           }, { 
           name: 'Berlin', 
           data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1] 
           }] 
         }); 

我必须通过ro_count,ro_free_count等代替“系列”中的'名称'和'arr [i] [j]'值而不是'数据'位置... JSON格式新增。

任何人都可以帮助我如何转换和传递这些值到这个图表应用程序。

+1

我假设你的意思是JavaScript而不是Java? – diagonalbatman 2011-01-10 11:24:23

+0

我需要关于如何将java变量值转换为json格式的任何示例。我现在清楚了吗?你可以提供任何示例程序 – Maya 2011-01-11 11:14:57

回答

0

最后,我写数据的,我需要通过这个图表应用到一个CSV文件,并将其传递给highchart如下:

String CSVFileToWrite = "../../MyCSVFile.csv";//file with .csv extension 
    String colkeys = "categories,jan,oct,nov"; 
    String rowKeys = "row1,row2"; 
    String[] row = rowKeys.split(","); 

    String[][] array = {{"250,340,456"}, {"123,567,789"}}; 
    System.out.print(array[0][0]); 
    System.out.println(""); 
    System.out.print(array[1][0]); 
    try { 
     File file = new File(CSVFileToWrite); 
     FileWriter fw1 = new FileWriter(file); 
     BufferedWriter bw = new BufferedWriter(fw1); 

     int col=0; 
     int row1=3; 
     int i=0; 
     String[][] arrayValues = new String[row1][1]; 
     arrayValues[0][0]=colkeys; 
     for(int r=1; r < row1 ;r++) { 
      arrayValues[r][col]=row[i] + "," + array[i][col]; 
      //System.out.println("ArrayValues["+r+"][" + col +"]" + arrayValues[r][col]); 
      i++; 
     } 
     for(int r=0 ; r < row1 ;r++) { 
      bw.write(arrayValues[r][col]); 
      bw.newLine(); 
      bw.flush(); 
     } 
     bw.close(); 
     System.out.println("File generated Successufully at location "+ file.getAbsolutePath()); 
    } catch (IOException ex) { 
    } 

这将创建一个名为CSV文件“MyCSVFile.csv”

,我包括在该文件到highcharts使用

$.get('MyCSVFile.csv',function(data) { 
} 

感谢&问候,

Maya