highcharts 饼图

js 部分

var Typeoptions = { 
        chart: {
        renderTo: 'materialTypeCount',//指向的div的id属性
            plotBackgroundColor: null,
            plotBorderWidth: null,
            type: 'pie',
            plotShadow: false
        },
        title: {
            text: ''
        },
        exporting: { enabled:false },
        credits: {
            enabled: false
        },
        tooltip: {
        pointFormat: '{point.y} 条'
        },
        plotOptions: {
            pie: {
            size:320,
                allowPointSelect: false,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.y} 条'
                },
                point : {
    events : {
    // 控制图标的图例legend不允许切换
    legendItemClick : function(event)
    {
                  return false; // return true 则表示允许切换
    }
}
    },
                showInLegend: true
            }
        },
        legend: {
        enabled:true,
        borderWidth: 1,
        floating:false ,
        useHTML:true
        }
    };

var brandPrices;
var  erencePrices;
var  periodicalPrices;
function getType() {
var series = {};
    chart = new Highcharts.Chart(Typeoptions);
chart.addSeries(series);
chart.showLoading('数据正在加载中...');
$.ajax({
type : "POST",
url : WEB_URL + '/getmaterialType',
data : {},
complete : function(response) {
var data = response.responseText;
if (false){
data = eval("(" + data + ")");
}
var result = data;
result = eval("(" + result + ")");
        var tresults = result.results;
        if(tresults[0] != null){
            brandPrices=tresults[0].brandPrices;
            erencePrices=tresults[0].erencePrices;
            periodicalPrices=tresults[0].periodicalPrices;
            series = {
                type: 'pie',
                data: [
                       ['Safari',   brandPrices],
                       ['Opera',   erencePrices],
                       ['Firefox',   periodicalPrices]
                       ]
            };
        }
            chart = new Highcharts.Chart(Typeoptions);
            chart.addSeries(series);
}
});
}


java 代码部分
@RequestMapping(value = "/getmaterialType")
@ResponseBody
public Object getmaterialType(){
Map<String, String> params = new HashMap<String, String>();
MaterialCount type = indexService.getmaterialType(params);
List<MaterialCount> newType = new ArrayList<MaterialCount>();
if(type != null){
MaterialCount m1 = new MaterialCount();
m1.setBrandPrices(type.getBrandPrices());
m1.setPeriodicalPrices(type.getPeriodicalPrices());
m1.setErencePrices(type.getErencePrices());
newType.add(m1);
}
return new Result(200, null, newType, "success");

}

你可能感兴趣的:(java)