我有以下方法我jquery。 调用jqplot的if块看起来不太好。 有没有更好的方法来解决这个问题?
onDealerSuccess: function (graphData, graphsDrpDwn, grphOneID, grphTwoID) {
/// <summary>This method is called on success of ajax call for dealer breakdown tab </summary>
/// <summary> This makes the necessary calls and plots the graph and bind the grid data </summary>
if (!graphData)
return;
var
grdYTcks = graphData["grdYTicks"].split(","),
grdXTcks = graphData["grdXTicks"].split(","),
mtrcXTcks = graphData["metricXTicks"].split(","),
mtrcYTcks = jQuery.parseJSON(graphData["metricYTicks"]),
YAxisLbl = "Grade";
// plot dealer graph
$.jqplot(grphOneID, [grdYTcks], YC.getGraphOpts(grdXTcks, YAxisLbl, m_CompositeReport.plotColors)).replot();
YAxisLbl = "Points";
// Sangeetha - Need to work on refactoring the below code
if (mtrcYTcks.length === 1)
$.jqplot(grphTwoID, [mtrcYTcks[0]], YC.getGraphOpts(mtrcXTcks)).replot();
if (mtrcYTcks.length === 2)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 3)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 4)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 5)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 6)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 7)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 8)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 9)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7], mtrcYTcks[8]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 10)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7], mtrcYTcks[8], mtrcYTcks[9]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 11)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7], mtrcYTcks[8], mtrcYTcks[9], mtrcYTcks[10]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 12)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7], mtrcYTcks[8], mtrcYTcks[9], mtrcYTcks[10], mtrcYTcks[11]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 13)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7], mtrcYTcks[8], mtrcYTcks[9], mtrcYTcks[10], mtrcYTcks[11], mtrcYTcks[12]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
if (mtrcYTcks.length === 14)
$.jqplot(grphTwoID, [mtrcYTcks[0], mtrcYTcks[1], mtrcYTcks[2], mtrcYTcks[3], mtrcYTcks[4], mtrcYTcks[5], mtrcYTcks[6], mtrcYTcks[7], mtrcYTcks[8], mtrcYTcks[9], mtrcYTcks[10], mtrcYTcks[11], mtrcYTcks[12], mtrcYTcks[13]], YC.getGraphOpts(mtrcXTcks, YAxisLbl, m_CompositeReport.stdColors)).replot();
YC.assignOvrw(graphData);
YC.bindGrid(graphData);
},