dojox.charting.Chart - labels on x axis from data?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

dojox.charting.Chart - labels on x axis from data?

neekfenwick
I'm a bit confused between the old docs for Chart2D and DataChart, and
the new dojox.charting.Chart stuff.  If I understand things right,
Chart2D and DataChart are 'old', and the 'new' Chart can do it all.

Following http://dojotoolkit.org/documentation/tutorials/1.6/charting/ 
and
http://dojotoolkit.org/documentation/tutorials/1.6/charting_advanced/ 
I've got my Chart up and running with a new fashioned dojo.store.

This sandbox is mostly from the tutorials, with some of my own data
thrown in.

http://dojo-sandbox.net/public/bdb64/0

So I have an 'x' axis set to natural: false, fixed: true.. I don't want
a continuous 'x' axis, they're going to be labelled with month names.  I
give the store data whose 'x' axis is a month number, and I want to
label them "Apr", "May", "Jun" etc.  The problem is that my months don't
always start at 1, say my data is a window of months 4 to 7.  I can give
an array of label names to the X axis object, but they are assigned
assuming the columns are numbered 1, 2, 3, 4, where my data clearly has
month values of 4, 5, 6, 7.

How can I get my columns labeled "Apr", "May", "Jun" etc., when the
series values that assign tha labels come from the data store, and are
not known at the time the X axis object is created?

I mean, I could fudge my code to pass "labels" specific to the data:

labels: [ { value: 1, text: 'May'}, { value: 2, text: 'Jun' }....

but this makes a mockery of data driven labelling.  I should be able to
use a fixed array of month names, and have the "month" value from the
data e.g. 5 be used to label that column from the "labels" element with
value===5.

I ran into the old labelFunc function, which is not mentioned in the new
documentation but does still seem to be in the code.  If you uncomment
labelFunc and comment out the l'labels' array in that sandbox, it'll
label them all "foo", but the values passed into the labelFunc dont seem
very useful.  From the code:

dojox.charting.scaler.common.getNumericLabel:
             if(kwArgs.labelFunc){
                 var r = kwArgs.labelFunc(def, number, precision);
                 if(r){ return r; }
                 // else fall through to the regular labels search
             }
             if(kwArgs.labels){
                 ... extract from 'labels' array based on

I'd be fairly happy with passing the "month" values in the data as
strings, i.e. "Jun" instead of 6, but I can't see how to label the
columns that way either.  The old "labelFunc: 'seriesLabels'" doesn't
work, and the documentation doesn't seem to cover this case.

The dojox/charting/tests/test_label2d.html file doesn't cover labelling
with custom labels from your data, and all their labels start with
"January" i.e. the first element in the hardcoded labels array.

The test_DataSeries.html file seems to hit the data source twice, once
for the data series and once with a store.fetch() to call makeSpinners
so it can construct a labels array to suit the data.  I'm guessing the
chart would also hit the data source as its 'addSeries' calls give it a
store to fetch from for that series.  That example adds one 'x' axis
with a simple addAxis() call during chart construction, then adds a
second 'x' axis in makeSpinners, after the chart has been rendered, with
labels based on the data.  Seems pretty weird to create two 'x' axes.  
Perhaps this is the only way to do what I'm trying to achieve?

The new documentation is fantastic, but I seem to be missing somthing
basic about my X axis definition, data, or labelling that eludes me.

Nick
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: dojox.charting.Chart - labels on x axis from data?

Eugene Lazutkin
chart.addXXX() with the same name replaces an old object. So your chart
doesn't contain two "x" axes, just one. Using addXXX() is a common idiom
to tweak object's attributes dynamically, e.g., change colors, or a
type, or anything else.

Right now there is no automatic provision to support labels derived from
data, specifically any dynamic label updates (if any) are up to you. If
you see a valid and reasonably frequent use case for that --- open an
enhancement ticket to encapsulate what you do manually. Right now it is
not here, because it is easy to implement in user's code.

Cheers,

Eugene Lazutkin
Dojo Toolkit, Committer
http://lazutkin.com/

On 07/23/2011 01:52 AM, Nick Fenwick wrote:

> I'm a bit confused between the old docs for Chart2D and DataChart, and
> the new dojox.charting.Chart stuff.  If I understand things right,
> Chart2D and DataChart are 'old', and the 'new' Chart can do it all.
>
> Following http://dojotoolkit.org/documentation/tutorials/1.6/charting/ 
> and
> http://dojotoolkit.org/documentation/tutorials/1.6/charting_advanced/ 
> I've got my Chart up and running with a new fashioned dojo.store.
>
> This sandbox is mostly from the tutorials, with some of my own data
> thrown in.
>
> http://dojo-sandbox.net/public/bdb64/0
>
> So I have an 'x' axis set to natural: false, fixed: true.. I don't want
> a continuous 'x' axis, they're going to be labelled with month names.  I
> give the store data whose 'x' axis is a month number, and I want to
> label them "Apr", "May", "Jun" etc.  The problem is that my months don't
> always start at 1, say my data is a window of months 4 to 7.  I can give
> an array of label names to the X axis object, but they are assigned
> assuming the columns are numbered 1, 2, 3, 4, where my data clearly has
> month values of 4, 5, 6, 7.
>
> How can I get my columns labeled "Apr", "May", "Jun" etc., when the
> series values that assign tha labels come from the data store, and are
> not known at the time the X axis object is created?
>
> I mean, I could fudge my code to pass "labels" specific to the data:
>
> labels: [ { value: 1, text: 'May'}, { value: 2, text: 'Jun' }....
>
> but this makes a mockery of data driven labelling.  I should be able to
> use a fixed array of month names, and have the "month" value from the
> data e.g. 5 be used to label that column from the "labels" element with
> value===5.
>
> I ran into the old labelFunc function, which is not mentioned in the new
> documentation but does still seem to be in the code.  If you uncomment
> labelFunc and comment out the l'labels' array in that sandbox, it'll
> label them all "foo", but the values passed into the labelFunc dont seem
> very useful.  From the code:
>
> dojox.charting.scaler.common.getNumericLabel:
>              if(kwArgs.labelFunc){
>                  var r = kwArgs.labelFunc(def, number, precision);
>                  if(r){ return r; }
>                  // else fall through to the regular labels search
>              }
>              if(kwArgs.labels){
>                  ... extract from 'labels' array based on
>
> I'd be fairly happy with passing the "month" values in the data as
> strings, i.e. "Jun" instead of 6, but I can't see how to label the
> columns that way either.  The old "labelFunc: 'seriesLabels'" doesn't
> work, and the documentation doesn't seem to cover this case.
>
> The dojox/charting/tests/test_label2d.html file doesn't cover labelling
> with custom labels from your data, and all their labels start with
> "January" i.e. the first element in the hardcoded labels array.
>
> The test_DataSeries.html file seems to hit the data source twice, once
> for the data series and once with a store.fetch() to call makeSpinners
> so it can construct a labels array to suit the data.  I'm guessing the
> chart would also hit the data source as its 'addSeries' calls give it a
> store to fetch from for that series.  That example adds one 'x' axis
> with a simple addAxis() call during chart construction, then adds a
> second 'x' axis in makeSpinners, after the chart has been rendered, with
> labels based on the data.  Seems pretty weird to create two 'x' axes.  
> Perhaps this is the only way to do what I'm trying to achieve?
>
> The new documentation is fantastic, but I seem to be missing somthing
> basic about my X axis definition, data, or labelling that eludes me.
>
> Nick
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: dojox.charting.Chart - labels on x axis from data?

neekfenwick
On 07/23/2011 02:09 PM, Eugene Lazutkin wrote:
> chart.addXXX() with the same name replaces an old object. So your chart
> doesn't contain two "x" axes, just one. Using addXXX() is a common idiom
> to tweak object's attributes dynamically, e.g., change colors, or a
> type, or anything else.

Thanks, that clears that up.  I hadn't seen that in any documentation or
code comments.

> Right now there is no automatic provision to support labels derived from
> data, specifically any dynamic label updates (if any) are up to you. If
> you see a valid and reasonably frequent use case for that --- open an
> enhancement ticket to encapsulate what you do manually. Right now it is
> not here, because it is easy to implement in user's code.

I would think the first thing one would want to do, after labelling data
based on a fixed array as in the examples, is to label points based on
the dataItem that gave the data for that point.

I'm not familiar with that old API so I'm not the best person to say
what it did or didn't do.

I've created http://bugs.dojotoolkit.org/ticket/13503

Since posting earlier, I've got a working sandbox doing what you
describe: http://dojo-sandbox.net/public/0a97b/1  .. it makes sense to
query the store for the labels and for the data series using an
identical query, so I use a consistent dataQuery object to encapsulate
the query (just {} in this simple example).. and also to query for, and
build, the labels array before constructing the chart so that only one
addAxis call need be issued.  I'll go ahead and build my app based on this.

Thanks
Nick
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: dojox.charting.Chart - labels on x axis from data?

Eugene Lazutkin
Inline.

On 07/23/2011 04:18 AM, Nick Fenwick wrote:
>
> I would think the first thing one would want to do, after labelling data
> based on a fixed array as in the examples, is to label points based on
> the dataItem that gave the data for that point.

From my experience the majority of cases use indirectly derived labels
--- either ordinals or date/time values. But custom data-derived
labeling is clearly quite common.

> I've created http://bugs.dojotoolkit.org/ticket/13503

Thank you.

> Since posting earlier, I've got a working sandbox doing what you
> describe: http://dojo-sandbox.net/public/0a97b/1  .. it makes sense to
> query the store for the labels and for the data series using an
> identical query, so I use a consistent dataQuery object to encapsulate
> the query (just {} in this simple example).. and also to query for, and
> build, the labels array before constructing the chart so that only one
> addAxis call need be issued.  I'll go ahead and build my app based on this.

It all sounds like a good plan to me. Let us know if you have more
questions, or need an advise on how to use charting in the most
efficient way. No matter how good the documentation is, real-life
applications are more complex than our examples, and frequently pushing
boundaries of browsers and libraries.

Cheers,

Eugene

>
> Thanks
> Nick
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest