미니카
636
2019-04-04 14:39:38
0
218

asp.net hightchart소스분석 헬프요 ㅠ


--- 컨트롤러

public JsonResult GetPfmAcidStatistics(

string fromYear,

string fromMonth,

string toYear,

string toMonth,

int plantNo = 0,

int deptNo = 0,

bool isDashBoard = false,

bool detail = false)

{

SpfmPortlet spfmPortlet = new SpfmPortlet();

IDictionary<string, object> data = spfmPortlet.GetPfmAcidStatistics(

fromYear,

fromMonth,

toYear,

toMonth,

plantNo,

deptNo,

isDashBoard,

detail);

return Json(data);

}

--

모델

public IDictionary<string, object> GetPfmAcidStatistics(

string fromYear,

string fromMonth,

string toYear,

string toMonth,

int plantNo,

int deptNo,

bool isDashBoard = false,

bool detail = false)

{

IDictionary<string, object> data = new Dictionary<string, object>();

PlantService plantService = new PlantService();

PfmItemService pfmItemService = new PfmItemService();

if (string.IsNullOrEmpty(fromYear) || fromYear == "0")

{

fromYear = DateTime.Now.AddYears(-1).ToString("yyyy");

fromMonth = DateTime.Now.AddYears(-1).ToString("MM");

toYear = DateTime.Now.AddMonths(-1).ToString("yyyy");

toMonth = DateTime.Now.AddMonths(-1).ToString("MM");

}

//차트 데이터

DataTable datatable = new DataTable();

//부서 실적 기준

if (plantNo > 0 && deptNo > 0)

{

datatable = pfmItemService.PfmItemStatisticsByDepartMonth(fromYear, fromMonth, toYear, toMonth, plantNo, deptNo);

}

//전사 실적 기준

else

{

//전사의 기준 사업장은 본사

Plant plant = plantService.SelectPlantInfo(Plant.PLANT_CODE_SEOUL);

datatable = pfmItemService.PfmItemStatisticsByCompanyMonth(fromYear, fromMonth, toYear, toMonth, plant.PlantNo, plantNo);

}

//Series, Points 수 계산

int monthCnt = Math.Abs((Convert.ToInt32(fromMonth) - Convert.ToInt32(toMonth)) + 12 * (Convert.ToInt32(fromYear) - Convert.ToInt32(toYear))) + 1;

int seriesCnt = datatable.Rows.Count / monthCnt;

List<string> seriesList = new List<string>();

IList<string> labelList = new List<string>();

IDictionary<string, IList<double>> dataList = new Dictionary<string, IList<double>>();

//데이터 세팅

for (int i = 0; i < datatable.Rows.Count; i++)

{

string seriesName = string.Empty;

IList<double> serieData = new List<double>();

//chart1.Data[i % seriesCnt, (i / seriesCnt) % monthCnt] = Convert.ToDouble(datatable.Rows[i]["REAL_VALUE"]);

serieData.Add(Convert.ToDouble(datatable.Rows[i]["REAL_VALUE"]));

if (i < seriesCnt)

{

//chart1.Series[i % seriesCnt].Text = Convert.ToString(datatable.Rows[i]["ITEM_NAME"]);

}

if (datatable.Rows[i]["ITEM_NAME"].ToString().Contains("TRIR") || datatable.Rows[i]["ITEM_NAME"].ToString().Contains("DAFWR"))

{

}

else

{

}

labelList.Add(Convert.ToString(datatable.Rows[i]["REG_DT"]));

}

data.Add("legend", seriesList);

data.Add("xCategories", labelList);

data.Add("seriesData", dataList);

return data;

}

-----------------

----------------------------

function createChart() {

$('#chart').empty();

var url = '@Url.Action("GetPfmAcidStatistics", "Prt")';

var param = {

'fromYear': $('#acidFromYear').val(),

'fromMonth': $('#acidFromMonth').val(),

'toYear': $('#toYear').val(),

'toMonth': $('#toMonth').val(),

'plantNo': $('#plantNo').val(),

'deptNo': '',

'isDashBoard': $('#IsDashboard').val() == 'Y',

'detail': false

}

var success = function (response, status, request) {

if (response['legend'].length > 0) {

var legend = response['legend'];

var xCategories = response['xCategories'];

var seriesData = [];

$.each(legend, function (index, item) {

seriesData.push({

name: item,

data: response['seriesData'][item],

label: {

enabled: false

}

});

});

var chartOptions = getHighchartDefOptionsOfPortlet({

'chart': {

'width': parseInt($('#Width').val(), 10),

'height': parseInt($('#Height').val(), 10) - 55,

},

'yAxis': {

'title': { 'text': '단위:건' }

},

'xAxis': {

'categories': xCategories

},

'tooltip': {

'valueSuffix': ' 건',

'shared': true,

'crosshairs': true

},

'series': seriesData

});

Highcharts.chart('chart', chartOptions);

}

else {

var $div = $('<div style="width:100%;text-align:center; vertical-align:middle;" />');

$div.css('line-height', (parseInt($('#Height').val(), 10) / 2) + 'px');

$div.text('조회된 데이터가 없습니다.');

$('#chart').append($div);

}

};

AjaxService.requestPost(url, param, success);

}

-----------------------------------------------------

모델에서 배열에 값넣는 법을 모르겠습니다


제발 도와주세요 ㅠ ㅠ

0
0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.