开发者

Java to JSON Format

This is my sample application which provides result as follows:

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

Since i have this 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, 开发者_JS百科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]
                              }]
                       });

I have to pass ro_count,ro_free_count,etc instead of 'name' in 'series' and 'arr[i][j]' values instead of 'data' place... Am new to JSON Format.

Can any one help me how to convert and pass these values to this chart application.


Finally, i wrote data's that i need to pass to this chart application into a csv file and passed it to the highchart as follows:

    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) {
    }

this will create a csv file called 'MyCSVFile.csv'

and i included this file into highcharts using

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

Thanks & Regards,

Maya

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜