首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义工具提示内容@ ngx-charts _ Angular2+ _ TypeScript

自定义工具提示内容@ ngx-charts _ Angular2+ _ TypeScript
EN

Stack Overflow用户
提问于 2018-07-27 11:36:43
回答 3查看 26.1K关注 0票数 20

我一直试图在一个线图表的工具提示中设置一个自定义标签,例如,修改HH:mm格式的分钟数(74分钟-> 1:14),但不幸的是,没有成功。将值显示为1.283(...3)并不是另一种选择。

编号至HH:mm作为工具提示标签

有人知道如何保存x和y轴值(日期和数字),并修改工具提示显示值吗?

例如:https://swimlane.github.io/ngx-charts/#/ngx-charts/line-chart

而不是有一个工具提示显示颜色,国家名称和数字,->颜色,国家名称和字符串(数字> 3000?“高”:“低”;)

当前行为按预期工作。

期望行为显示自定义标签。

上面描述中问题链接的复制

更改行为的动机/用例是什么?能够自定义工具提示的内容

请告诉我们您的环境: OS: Win 10 x64,IDE: Eclipse

ngx-图表版本: 3.0.2

角版: 6.0.2

浏览器: all

语言: TypeScript 2.3.3

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-07-31 11:51:01

您可以定义自己的工具提示模板,并在其中呈现任何您喜欢的HTML:

代码语言:javascript
复制
<ngx-charts-line-chart        
    [scheme]="colorScheme"
    [results]="multi" ...>
  <ng-template #tooltipTemplate let-model="model">
    This is the single point tooltip template
    <pre>{{model|json}}</pre>
  </ng-template>

  <ng-template #seriesTooltipTemplate let-model="model">
    This is vertical line tooltip template
    <pre>{{model|json}}</pre>        
  </ng-template>
</ngx-charts-line-chart>

示例:https://swimlane.github.io/ngx-charts/#/ngx-charts/tooltip-templates

代码在这里:https://github.com/swimlane/ngx-charts/blob/8ebb3dbcbbea443fefdcafd1f5c9069df0e0c4ae/src/app/app.component.html#L992-L998

票数 47
EN

Stack Overflow用户

发布于 2019-05-17 20:09:27

以上解决方案不适用于多维图表(> 3),如叠加的水平/垂直条。

另一种适用于所有情况的简单方法是将tooltipText作为模型的一部分添加到属性中,如下所示:

代码语言:javascript
复制
export let multi = [
  {
    name: 'Germany',
    series: [
      {
        name: '2010',
        value: 7300000,
        tooltipText: 't1'
      },
      {
        name: '2011',
        value: 8940000,
        tooltipText: 't2'
      }
    ]
  }
];

然后在标记中使用以下代码,

代码语言:javascript
复制
<ngx-charts-bar-horizontal-stacked
      [view]="view"
      [scheme]="colorScheme"
      [results]="multi"
      [gradient]="gradient"
      [xAxis]="showXAxis"
      [yAxis]="showYAxis"
      [legend]="showLegend"
      [legendPosition]="legendPosition"
      [showXAxisLabel]="showXAxisLabel"
      [showYAxisLabel]="showYAxisLabel"
      [xAxisLabel]="xAxisLabel"
      [yAxisLabel]="yAxisLabel"
      (select)="onSelect($event)">
  <ng-template #tooltipTemplate let-model="model">
    <div class="tooltip">
      {{model.tooltipText}}
    </div>
  </ng-template>
</ngx-charts-bar-horizontal-stacked>
票数 3
EN

Stack Overflow用户

发布于 2018-08-16 16:51:17

再次谢谢你。不想让这个问题得不到解决。问题是,代码片段在svg元素中。以下是最终版本:

代码语言:javascript
复制
<!--  This is single point tooltip template -->
<xhtml:ng-template #tooltipTemplate let-model="model">
  <xhtml:div class="area-tooltip-container">
    <xhtml:div *ngFor="let tooltipItem of model | json | durationHhmm" class="tooltip-item" style="text-align: center;">
      <a style=" font-size: 1.2em;">{{tooltipItem.series}}</a><a *ngIf="tooltipShowTime==='DAY' || tooltipShowTime==='WEEK'" style=" font-size: 1.2em;"><br />{{tooltipItem.name | date: 'HH:mm'}} Uhr</a><a *ngIf="tooltipShowTime!=='DAY' && tooltipShowTime!=='WEEK'" style=" font-size: 1.3em; font-weight: 600;"><br />&#183;</a><br /><a style=" font-size: 1.2em; font-weight: 600;">{{tooltipItem.name | date: 'dd.MM.yyyy'}} &#183; </a><a style=" font-size: 1.3em; font-weight: 600;">{{tooltipItem.value}}</a>
    </xhtml:div>
  </xhtml:div>
</xhtml:ng-template>

<!-- Datapoints Y-Axis -->
<svg:g *ngFor="let series of data">
  <svg:g ngx-charts-circle-series
         [xScale]="xScale"
         [yScale]="yScale"
         [colors]="colors"
         [data]="series"
         [scaleType]="scaleType"
         [visibleValue]="hoveredVertical"
         [activeEntries]="activeEntries"
         [tooltipDisabled]="tooltipDisabled"
         [tooltipTemplate]="tooltipTemplate"
         (select)="onClick($event, series)"
         (activate)="onActivate($event)"
         (deactivate)="onDeactivate($event)"
  /> 
</svg:g>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51557129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档