2013-05-19 2 views
0

기존 jqPlot 객체에 새로운 시리즈를 동적으로 추가 할 수 있습니까?jqPlot : 새 시리즈를 동적으로 추가 할 수 있습니까?

나는이 시리즈를 검색 할 수 AJAX 데이터 렌더러를 사용하는 jqPlot 객체가 있습니다. 이 부분은 잘 작동합니다.

사용자 입력 (여러 매개 변수)를 기반으로 동적으로 추가하거나 (두 개의 원본을 유지하면서) 차트에 추가 시리즈를 제거 할 수 있도록하고 싶습니다.

이것이 가능합니까? 다시 원래의 두 줄에 대한 변경되지 않은 데이터를 검색하지 않고도 가능합니까? 이것이 가능하지 않은 경우

또한,이 작업을 수행 할 수있는 다른 차트 라이브러리에 대한 권장 사항이 있습니까?

답변

2

는 네, 난 그냥이 작업을 수행하는 방법을 발견, 나는 당신의 질문을 발견하고, 응답이 없었다, 그래서 난 내을 제공 할 것입니다. 자, 이것이 아마도 가장 우아한 방법은 아니지만 작동합니다.

$(document).ready(function() { 

    DataSeriesToPlot = [[[x1_1,y1_1],[x1_2,y1_2]],[[x2_1,y2_1],[x2_2,y2_2]], 
    [[x3_1,y3_1], [x3_2,y3_2]]]; 
    AxesOptions = { 
     xaxis: {min: xmin, max: xmax}, 
     yaxis: {min: ymin} 
    }; 
    PlotTitle = 'PlotTitle', 
    PlotSeriesDefaults = { 
     showMarker: false, 
     shadow: false, 
     rendererOptions: { 
      smooth: true 
     } 
    }; 
    PlotLegend = { 
     show: true, 
     labels: ['label1','label2','label3'] 
    }; 
    PlotSeriesOptions = [ 
     { 
      linePattern: 'dashed', 
      color: '#f80202', 
     }, 
     { 
      linePattern: 'dashed', 
      color: '#f80202', 
     }, 
     { 
      color: '#f80202', 
     } 
    ]; 

    PlotVar = $.jqplot('Plotdiv', DataSeriesToPlot, 
    { 
     axes: AxesOptions, 
     title: PlotTitle, 
     seriesDefaults: PlotSeriesDefaults, 
     series: PlotSeriesOptions, 
     legend: PlotLegend 
    }); 

AddToPlot(); 

}); 

function AddToPlot(){ 

    $("Plotdiv").empty(); 
    DataSeriesToPlot.push([[x4_1,y4_1],[x4_2,y4_2]]); 
    PlotLegend.labels.push('label4'); 
    PlotSeriesOptions.push({ 
     linePattern: 'dashed', 
     color: '#ff6600', 
    }); 

    PlotVar = $.jqplot('Plotdiv', DataSeriesToPlot, 
    { 
     axes: AxesOptions, 
     title: PlotTitle, 
     seriesDefaults: PlotSeriesDefaults, 
     series: PlotSeriesOptions, 
     legend: PlotLegend 
    }); 
}