Ngx-charts: Logarithmic scale for time series line chart

Created on 12 Feb 2020  路  3Comments  路  Source: swimlane/ngx-charts

Hi,

I have successfully implemented a timeseries line chart using ngx-charts. The timeseries is plotted on the X-axis and the values on Y-axis. Now I have a requirement to change the Y-axis to logarithmic scale.

Any pointers would be appreciated.

Thanks
Merin

Most helpful comment

Hi,

here's a demo how to implement log scale in line chart based on @chriszrc's comment https://github.com/swimlane/ngx-charts/pull/455#issuecomment-626800581

https://stackblitz.com/edit/swimlane-line-chart-log-scale

  • manually apply Math.log10 to series data
  • define yAxisTickFormatting with Math.pow function
  • define tooltipTemplate and seriesTooltipTemplate templateRef using Math.pow function

Anyway, I submit pull request https://github.com/swimlane/ngx-charts/pull/1420 where yAxisTickFormatting is applied to tooltip values so you don't need to define tooltipTemplate and seriesTooltipTemplate.

IMO, if you define yAxis ticks as apples, pears, rates, pow, etc... you want that tootlip values are displayed as apples, pears, rates, pow, etc...

All 3 comments

I also have the requirement to have logarithmic scale. @merinshaji were you able to find workaround for the time being?

Hi,

here's a demo how to implement log scale in line chart based on @chriszrc's comment https://github.com/swimlane/ngx-charts/pull/455#issuecomment-626800581

https://stackblitz.com/edit/swimlane-line-chart-log-scale

  • manually apply Math.log10 to series data
  • define yAxisTickFormatting with Math.pow function
  • define tooltipTemplate and seriesTooltipTemplate templateRef using Math.pow function

Anyway, I submit pull request https://github.com/swimlane/ngx-charts/pull/1420 where yAxisTickFormatting is applied to tooltip values so you don't need to define tooltipTemplate and seriesTooltipTemplate.

IMO, if you define yAxis ticks as apples, pears, rates, pow, etc... you want that tootlip values are displayed as apples, pears, rates, pow, etc...

@heyteacher thanks a lot for the help. The code link helped me understand where exactly to make the changes hence made changes in bar graph accordingly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azarus picture azarus  路  4Comments

emeric0101 picture emeric0101  路  3Comments

NashIlli picture NashIlli  路  3Comments

ianfdk picture ianfdk  路  3Comments

stephanrauh picture stephanrauh  路  4Comments