Giter Club home page Giter Club logo

Comments (7)

slestang avatar slestang commented on May 18, 2024 4

It might be useful for other people that want to use recharts for timeseries that I specify my other work-around.

By default XAxis is of type category so I cannot specify it's domain and it isn't linear; if I have points every minutes with a 5 minutes hole in in the middle, the graph will display a hole of a duration of 1minute :-( .

I try using a number axis and specify the domain but it doesn't work because of the way recharts is done.

So I end up using a category x axis but I manually ensure that they are a point every minutes of my whole domain, with some point having an undefined value.

from recharts.

xile611 avatar xile611 commented on May 18, 2024 1

@slestang
Maybe your case can be implemented by set customized ticks and tickFormatter in XAxis.

http://jsfiddle.net/ntmm30gk/

from recharts.

xile611 avatar xile611 commented on May 18, 2024

Thanks! @slestang
Can you show me your code, and how you want to use recharts?

from recharts.

slestang avatar slestang commented on May 18, 2024

My slightly simplified Chart component:

const Chart = ({ values }) =>
  <div style={{ height: '10rem' }}>
    <ResponsiveContainer >
      <LineChart
          data={values}
          margin={{ top: 5, right: 0, bottom: 0, left: 0 }}
      >
        <Line type="linear" dataKey="value" stroke="#8884d8" dot={false} />
        <CartesianGrid stroke="#ccc" strokeDasharray="5 5" />
        <XAxis dataKey="time" tickFormatter={tickFormatDate}/>
        <YAxis dataKey="value" tickFormatter={twoDigitsWithMetricPrefix}/>
        <Tooltip
            formatter={twoDigitsWithMetricPrefix}
            labelFormatter={tickFormatDate}
            wrapperStyle={{ width: 100, backgroundColor: '#ccc' }}
        />
      </LineChart>
    </ResponsiveContainer>
  </div>

Where values is an array of {time: Date, value: Number} and tickFormatDate is a function very close to d3.time.format.multi(formats).

The component is working but the ticks aren't at round time:
recharts_timeseries

A similar chart using NVD3 with ticks each 5 minutes:
nvd3_timeseries

I also like to be able to choose the number of ticks for each axis, or precise that I want more of them.

Thanks for your work!

from recharts.

xile611 avatar xile611 commented on May 18, 2024

Thanks! I 'll think about supporting scaleTime.

from recharts.

slestang avatar slestang commented on May 18, 2024

Thanks @xile611
It works with a minor modification, my time property need to be a timestamp instead of Date.

from recharts.

olelivalife avatar olelivalife commented on May 18, 2024

It might be useful for other people that want to use recharts for timeseries that I specify my other work-around.

By default XAxis is of type category so I cannot specify it's domain and it isn't linear; if I have points every minutes with a 5 minutes hole in in the middle, the graph will display a hole of a duration of 1minute :-( .

I try using a number axis and specify the domain but it doesn't work because of the way recharts is done.

So I end up using a category x axis but I manually ensure that they are a point every minutes of my whole domain, with some point having an undefined value.

I know this is old... But how did you ensure points every 5 min? I tried setting ticks for my domain manually, but it doesn't work :(

from recharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.