2017-11-28 5 views
0

3つの異なるデータソースを持つグラフを表示する必要があります。私は、同じグラフ上に3つのデータソース、あるいは2つか1つのデータソースをすべて表示する必要があります。各dataSourceの値は、y軸の値がなく、x軸がdateTimeのように変化します。 誰でも私にこれを助けることができますか?devExpressチャートを使用して同じグラフ上に複数のdataSourceを処理する方法はありますか

答えて

0

3つの異なるデータソースの値をランダムに生成したサンプルコードです。 htmlとtsファイルのコードは、下記のコードブロックにあります。

HTMLコード

<div style="text-align: center"> 
    <label class="checkbox-inline text-danger"><input type="checkbox" checked (click)="showOne()"><b> Audio</b></label> 
    <label class="checkbox-inline text-success"><input type="checkbox" checked (click)="showTwo()"><b> Frozen</b></label> 
    <label class="checkbox-inline text-info"><input type="checkbox" checked (click)="showThree()"><b> Color</b></label> 
</div> 
    <div id="popup"> 
     <dx-chart id="chart" [dataSource]="devGraphData" 
     [animation]="false" 
     zoomingMode="all" scrollingMode="all"> 
     <dxo-size [height]="300"></dxo-size> 
     <dxi-value-axis [valueMarginsEnabled]="true" > 
     <dxo-grid [visible]="false"></dxo-grid></dxi-value-axis> 
     <dxi-series type="area" valueField="value1" name="data1" color="red"><dxo-point [visible] = false></dxo-point></dxi-series> 
     <dxi-series valueField="value2" name="data2" color="green"><dxo-point [visible] = true symbol="triangleDown"></dxo-point></dxi-series> 
     <dxi-series valueField="value3" name="data" color="blue"><dxo-point [visible] = true></dxo-point></dxi-series> 
     <dxo-common-series-settings argumentField="index" type="line" tagField="data"></dxo-common-series-settings> 
     <dxo-argument-axis [valueMarginsEnabled]="false"></dxo-argument-axis> 
     <dxo-tooltip [enabled]="true"></dxo-tooltip> 
     <dxo-legend [visible]="false"></dxo-legend> 
     <dxo-scroll-bar [visible]="true"></dxo-scroll-bar> 
     </dx-chart> 
    </div> 

TSコード

export class MultiChartComponent { 
    devGraphData: MultiChartComponent[] = []; 
    devGraphData1: MultiChartComponent[] = []; 
    devGraphData2: MultiChartComponent[] = []; 
    devGraphData3: MultiChartComponent[] = []; 
    devGraphIndex: number = 0; 
    devGraphIndex2: number = 0; 
    devGraphIndex3: number = 0; 
    devData: any; 
    firstChart: boolean = false; 
    secondChart: boolean = false; 
    thirdChart: boolean = false; 

    constructor(public globalService:GlobalService) { 
     Observable.interval(3000).subscribe(x => { 
      this.getData(0,1); 
     }); 
     Observable.interval(3000).subscribe(x => { 
      this.getData(2,3); 
     }); 
     Observable.interval(3000).subscribe(x => { 
      this.getData(4,5); 
     }); 
     this.showOne(); 
     this.showTwo(); 
     this.showThree(); 
    } 

    public getData(minValue: any, maxValue: any) { 
     this.devGraphIndex = this.devGraphIndex + 1; 
     if (minValue === 0 && maxValue === 1) { 
      this.devData = { 'index': this.devGraphIndex, 'value1': this.getRandomInt(minValue, maxValue)}; 
      this.devGraphData1.push(this.devData); 
      this.concatArrays(); 
      if(this.devGraphData1.length > 50) { 
       this.devGraphData1.splice(0, 1); 
      } 
     } 
     if (minValue === 2 && maxValue === 3) { 
      this.devData = { 'index': this.devGraphIndex, 'value2': this.getRandomInt(minValue, maxValue) }; 
      this.devGraphData2.push(this.devData); 
      this.concatArrays(); 
      if(this.devGraphData2.length > 50) { 
       this.devGraphData2.splice(0, 1); 
      } 
     } 
     if (minValue === 4 && maxValue === 5) { 
      this.devData = { 'index': this.devGraphIndex, 'value3': this.getRandomInt(minValue, maxValue) }; 
      this.devGraphData3.push(this.devData); 
      this.concatArrays(); 
      if(this.devGraphData3.length > 50) { 
       this.devGraphData3.splice(0, 1); 
      } 
     } 
    } 

    public getRandomInt(min:any, max:any) { 
     return Math.abs(Math.random() * (max - min + 1)) + min; 
    } 

    public showOne() { 
     this.devGraphData = []; 
     if (this.firstChart === true) { 
      this.firstChart = false; 
     } else { 
      this.firstChart = true; 
     } 
     this.concatArrays(); 
    } 

    public showTwo() { 
     this.devGraphData = []; 
     if (this.secondChart === true) { 
      this.secondChart = false; 
     } else { 
      this.secondChart = true; 
     } 
     this.concatArrays(); 
    } 

    public showThree() { 
     this.devGraphData = []; 
     if (this.thirdChart === true) { 
      this.thirdChart = false; 
     } else { 
      this.thirdChart = true; 
     } 
     this.concatArrays(); 
    } 

    public concatArrays() { 
     if(this.firstChart === true && this.secondChart === true && this.thirdChart === true) { 
      this.devGraphData = this.devGraphData2.concat(this.devGraphData3); 
      this.devGraphData = this.devGraphData.concat(this.devGraphData1); 
     } else if(this.firstChart === true && this.secondChart === true) { 
      this.devGraphData = this.devGraphData1.concat(this.devGraphData2); 
     } else if(this.secondChart === true && this.thirdChart === true) { 
      this.devGraphData = this.devGraphData2.concat(this.devGraphData3); 
     } else if(this.firstChart === true && this.thirdChart === true) { 
      this.devGraphData = this.devGraphData1.concat(this.devGraphData3); 
     } else if(this.firstChart === true) { 
      this.devGraphData = this.devGraphData.concat(this.devGraphData1); 
     } else if(this.secondChart === true) { 
      this.devGraphData = this.devGraphData.concat(this.devGraphData2); 
     } else if(this.thirdChart === true) { 
      this.devGraphData = this.devGraphData.concat(this.devGraphData3); 
     } 
    } 
} 
関連する問題