Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date time format %Y-%m-%d %H:%M:%S to create line chart #17

Open
arvind111 opened this issue Oct 12, 2015 · 7 comments
Open

date time format %Y-%m-%d %H:%M:%S to create line chart #17

arvind111 opened this issue Oct 12, 2015 · 7 comments

Comments

@arvind111
Copy link

Hi Pyxley Team ,

first of all congratulation for the Wonderfull framework . I have one query here if i would like to create a line chart given in example metricsgraphics with date - time(x- axis) so what should be format of Date Column in the csv file for date - time(x axis) .
dateparse = lambda x: pd.datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
df = pd.read_csv("fitbit_data.csv", parse_dates=['Date'], date_parser=dateparse)
sf = df.set_index("Date").stack().reset_index()
i have already tried but line charts failed with Date as %Y-% m-%d %H:%M:%S. line charts only works well with date format as %Y-% m-%d .

@arvind111 arvind111 changed the title date time for to create line chart with date and time date time format %Y-%m-%d %H:%M:%S to create line chart Oct 12, 2015
@nperony
Copy link

nperony commented Oct 21, 2015

Hi, another Pyxley user here. At Tamedia Digital (Zurich), the data science team is planning to use Pyxley for quick dashboard implementation. We'd love to see datetimes supported for line charts. Thanks!

@sanjeevbhalla
Copy link

Another user who is using Pyxley and ran into this same issue. One should be allowed to specify the date format of the data.

@nmkridler
Copy link
Contributor

I think the problem is that I'm casting a string to a Date. You should be able to format however you like, it just needs to be a string when it's transmitted to the javascript. I can probably force that in the default request function.

@sanjeevbhalla
Copy link

No. I tried string and it did not work. If I recall right the problem is
that the MG date formatting function that is called from d3 expects a
format and without a format passed it assumes a default of Y M and D. That
is my recollection when I tried to understand whats going on.

Thanks

On Thu, Jan 7, 2016 at 8:23 AM, Nick Kridler [email protected]
wrote:

I think the problem is that I'm casting a string to a Date. You should be
able to format however you like, it just needs to be a string when it's
transmitted to the javascript. I can probably force that in the default
request function.


Reply to this email directly or view it on GitHub
#17 (comment).

@nmkridler
Copy link
Contributor

Here's the javascript code that does the conversion.

    _update: function(params) {
        d3.json(this.props.options.url.concat("?",$.param(params)),
            function(error, data){
                var options = this.props.options.params;
                if(data.date){
                    for(var i=0; i < data.result.length; i++){
                        data.result[i] = MG.convert.date(data.result[i], "x");
                    }
                }
                options.data = data.result;
                MG.data_graphic(options);
            }.bind(this));
    },

https://github.com/stitchfix/pyxleyJS/blob/master/src/metricsgraphics.js

I'll have to look in to it and try it with different date formatting.

@sanjeevbhalla
Copy link

Right. On this line data.result[i] = MG.convert.date(data.result[i], "x"); is
called to convert Date. But because no format is passed it uses default
format of %Y-%m-%d

https://github.com/mozilla/metrics-graphics/wiki/Convenience-Functions
Converts a data object's values from strings to javascript Date objects
that can then be plotted. The function parses %Y-%m-%d-styled timestamps by
default. An optional third argument allows one to specify an alternative
style, per the formats defined here:
How do I as user of Pyxley override this behavior? (Sorry if I am missing
something obvious - I am not a Javascript expert).

Thanks for your help.

On Thu, Jan 7, 2016 at 8:47 AM, Nick Kridler [email protected]
wrote:

Here's the javascript code that does the conversion.

https://github.com/stitchfix/pyxleyJS/blob/master/src/metricsgraphics.js


Reply to this email directly or view it on GitHub
#17 (comment).

@markosole
Copy link

This worked for me:

for(var i = 0; i < data.length; i++) {
                    data[i] = MG.convert.date(data[i], 'date', '%Y-%m-%dT%H:%M:%SZ'); 
 }

My date in database looks like this: 2018-04-28T13:24:55Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants