faizanjehangir
faizanjehangir

Reputation: 2841

Show time series data with primeng

I want to plot a time series data (on a line chart), similar to this:

[
   {year: 2008, value: 0.07686},
   {year: 2008, value: 0.08636},
   {year: 2009, value: 0.096889},
   {year: 2009, value: 0.01234},
   {year: 2010, value: 0.06686},
   ....
]

Where the year will go along x-axis and value on y-axis. The documentation only discusses about defining the labels on x and the respective values along y. Would defining a single label, 2008 in this case, along with its dataset: 0.07686, 0.08636 work? Is it supported by the framework?

Upvotes: 0

Views: 1022

Answers (1)

happyZZR1400
happyZZR1400

Reputation: 2405

Dont know if it consider "work" for you, but you can do something like this:

constructor() {
  let other = [
    {year: 2008, value: 0.07686},
    {year: 2008, value: 0.08636},
    {year: 2009, value: 0.096889},
    {year: 2009, value: 0.01234},
    {year: 2010, value: 0.06686},      
  ]


  this.data = {
          labels: other.map(y=>y.year),
          datasets: [
              {
                  label: 'First Dataset',
                  data: other.map(y=>y.value)
              }
          ]
      }
  }

look at this stackblitz

Upvotes: 1

Related Questions