简体   繁体   English

Highcharts 创建自定义下拉范围选择器/日期选择器

[英]Highcharts create custom dropdown range selector / date picker

I want to create a custom dropdown range selector for my graph.我想为我的图表创建一个自定义下拉范围选择器。 For Example: rather than the default range selector given by the Highcharts.例如:而不是 Highcharts 给出的默认范围选择器。 I want to have it as the image shown.我想要它如图所示。 I tried creating a html options however, the chart.update does not work on my code .ts file.我尝试创建一个 html 选项,但是,chart.update 不适用于我的代码 .ts 文件。 How can I have the same output as the image shown.我怎样才能有与显示的图像相同的输出。

highstock.ts highstock.ts

export class HighchartStockComponent {
  public resultSetOptions: TruCoreSelectOptionInterface[] = [
    {
      options: [
        {label: '1m', value: '0', selected: true},
        {label: '3m', value: '1'},
        {label: '6m', value: '2'},
        {label: 'YTD', value: '3'},
        {label: 'All', value: '5'},
      ],
    },
  ];

  @Input() chartOptions: Options;
  chart: Chart;

  Highcharts: typeof Highcharts = Highcharts;
 constructor() {
this.Highcharts.setOptions({
      exporting: {
        showTable: true,
        csv: {
          dateFormat: '%Y-%m-%d',
        },
      },
      chart: {
        style: {
          fontFamily: '"Graphik Regular", sans-serif',
          fontSize: '12px',
          fontWeight: 'normal',
        },
     
        
      },
      
      lang: {
        thousandsSep: '\u066C',
        rangeSelectorZoom: '',
        // rangeSelectorFrom: 'From',
        // rangeSelectorTo: 'To'
      },
    });
  }
 // range(event) {
  //   if (event) {
  //     this.chart.update({
  //       rangeSelector: {
  //         selected: event.value,
  //       },
  //     });
  //   }
  // }
 
}

highstock.html highstock.html

<mat-tab-group class="mat-tab--retail tru-core-margin-left--md tru-core-margin-right--md" animationDuration="0ms">
  <mat-tab label="Graph" class="mat-table--retail">
    <tru-core-grid class="container">
      <div class="range-selector">
        <tru-core-select
          id="range"
          [options]="resultSetOptions"
          (truCoreSelectChange)="range($event)"
          class="tru-core-margin-left--xs tru-core-margin-right--xs"
        >
        </tru-core-select>
      </div>
      <highcharts-chart id="chart" [Highcharts]="Highcharts" [constructorType]="'stockChart'" [options]="chartOptions" style="overflow: scroll;">
      </highcharts-chart>
    </tru-core-grid>
  </mat-tab>

image图片

Simplifying how to build custom options, inside the ts file next to the class you are exporting build something similar:简化如何构建自定义选项,在您要导出的类旁边的 ts 文件中构建类似的内容:

options = [
  [1.2e3, '1.2s'],
  [24e3, '24s'],

  [12e4, '2m'],
  [24e4, '4m'],
  [48e4, '8m'],
  [72e4, '12m'],
  [144e4, '24m'],
  [216e4, '36m'],

  [36e5, '1h'],
  [216e5, '6h'],
  [432e5, '12h'],

  [86.4e6, '1d']
];

// changing the range from dropdown
rangeChange(event) {
  
}

At your HTML template:在您的 HTML 模板中:

<div class="range-selector-btn-dropdown">
    Zoom view: 
    <select id="range-selector-btn" 
    (change)="rangeChange($event)"
    [(ngModel)]="selectedValue">
        <option *ngFor="let option of options;"
        [value]="option[0]">{{option[1]}}</option>
   </select>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM