keen / keen-js

https://keen.io/ JavaScript SDKs. Track users and visualise the results. Demo http://keen.github.io/keen-dataviz.js/
MIT License
578 stars 143 forks source link

Viz parameter for sorting? #109

Closed wetzler closed 10 years ago

wetzler commented 10 years ago

The visualization library automatically sorts my results for bar charts, ranking them from high to low. However, there are some times when I don't want them ranked, like this example:

How can I specify the order in which results are charted in the visualization?

screen shot 2014-07-13 at 3 41 58 pm

I would like the results on the bottom to go from 0 to 10.

dustinlarimer commented 10 years ago

@wetzler totally agree!

Btw, is that a single group_by query?

ruleant commented 10 years ago

:+1: :) I'm experiencing a similar problem : https://github.com/ruleant/buildtime-trend/issues/40

Would it be possible to disable or change the current default sorting behavior when drawing a chart with a parameter and rely on the order of the array with result that is passed to the draw function?

Fe. sorting : value (vAxis), index (hAxis), none (use order of result array)

Something to keep in mind : sorting behaviour in case of value when there are multiple data series.

dustinlarimer commented 10 years ago

@wetzler @ruleant just wanted to let you know this has been incorporated in the upcoming v3.1 release – good things on the way :)

wetzler commented 10 years ago

Github does not have a "like" button :heart:

Ps - I wrote a workaround for this if we need to share it. Sounds like we won't since a new version is coming out. :)

ruleant commented 10 years ago

Cool! Looking forward to the 3.1 release.

BTW : I found out that in charts with multiple data series, the data is not ordered by value but by the order of the supplied array (or on the index, I didn't check). See https://github.com/ruleant/buildtime-trend/issues/26 (I tweeted you about it a few weeks ago as well).

Anyway, having this feature will be really useful for future custom charts. :)

Thanks!

davidbcook commented 10 years ago

+1 Will we be able to sort alphabetically?

dustinlarimer commented 10 years ago

@davidbcook yep, sure will! You can sort alphabetically by label or value (group_by), or by the sum of each series (group_by + interval).

dustinlarimer commented 10 years ago

This has been added in the v3.1.0-beta release. Docs are also in the branch now.. dig in and please share any issues or questions you may have!

ruleant commented 10 years ago

@dustinlarimer I've tested the new beta release, and it looks like this in my project (changing nothing but the link to the new library) : http://ruleant.github.io/buildtime-trend/buildtime-trend/keenjs-3.1-beta.html Do you prefer a list of issues I've found, or shall I create an issue on github for each of them?

dustinlarimer commented 10 years ago

@ruleant is everything loading as you expect? Metrics

Keep in mind the new sorting functionality you're looking for will be part of the new Keen.Dataviz object. The interface is doc'd and I've begun assembling a pile of jsFiddles to demonstrate what this thing can do: http://jsfiddle.net/user/keen/fiddles/

As for issues, let's dump everything into one running issue for now.. sound good?

Thanks for checking this out!

dustinlarimer commented 10 years ago

@ruleant --> https://github.com/keenlabs/keen-js/issues/175

fraank commented 9 years ago

Hey, is sorting or ordering (with direction ASC / DESC) by result or a special column now possible? I cannot find it in the docs. I'm using the ruby-wrapper for the API. Thanks!

dustinlarimer commented 9 years ago

@fraank yep, it's available now: https://github.com/keen/keen-js/blob/master/docs/dataviz.md#sortgroupsstring

dustinlarimer commented 9 years ago

@fraank let me know if I can help!

ckreutz commented 9 years ago

Hello! I use 3.10 and added sortGroups: "asc", but it is sorted by the targetProperty and not by groupBy values. How can I change that?

dustinlarimer commented 9 years ago

Hey, @ckreutz – can you share a sample code snippet (or jsFiddle if possible) so I can dig in a little deeper?

ckreutz commented 9 years ago

Sure. Thanks for taking a look!

Keen.ready(function(){
     var disb_years = new Keen.Query("sum", {
          eventCollection: "crs",
          targetProperty: "usd_disbursement",
          groupBy: "Year",
          filters: [{"property_name":"recipientname","operator":"eq","property_value": "Egypt"}]
      });
        client.draw(disb_years, document.getElementById("disb_years"), {
            title: false,
            chartType: "areachart",
            height: 250,
            width: "auto",
            sortGroups: "asc",
            chartOptions: {
              chartArea: {
                height: "85%",
                left: "5%",
                top: "5%",
                width: "80%"
              }
            }
        }); 

The output is sorted by "usd_disbursement" and not "Year".

dustinlarimer commented 9 years ago

@ckreutz ahh ok, yeah that's working as expected.. it's sorting groups by their values. You can operate on the underlying data object with more flexibility and control w/ the Keen.Dataset instance. client.draw() constructs and returns one of these, but constructing manually gives you a chance to do this before the chart is rendered.

Here's a jsFiddle that demonstrates how to do this: http://jsfiddle.net/keen/knn6gcpg/

Let me know if I can help any further! dustin@keen.io

dustinlarimer commented 9 years ago

@ckreutz also note the client.run method's callback signature in that fiddle is (err, res), which was changed in v3.2. I don't think this will snag you, but something to keep in mind, in case you hit any odd errors.

ckreutz commented 9 years ago

@dustinlarimer thanks so much. Works perfect.

dustinlarimer commented 9 years ago

@ckreutz awesome, happy to hear that!