If your original DataTable has numbers in the first column, you can create a
DataView over the data table which returns the values as strings.  When you
sort the DataTable, the DataView will automatically be updated.  As in the
following code:

var data = new g.v.DataTable();
data.addColumn('number');
data.addColumn('number');
data.addRows(rows);
var view = new g.v.DataView(data);
view.setColumns([{type: 'string', calc: function(d, row) { return
d.getFormattedValue(row, 0); }}, 1]);
data.sort(0);

(If you want to do something more efficient but less readable, see
getSortedRows()).

On Mon, Nov 29, 2010 at 4:44 AM, chrissky <[email protected]> wrote:

> Plan B: just clone the whole table but change the string type column
> to a numeric. And use that cloned table for the chart. I have used
> that approach on several occasions.
>
> On Nov 28, 4:44 am, Lukáš Kubín <[email protected]> wrote:
> > Thanks chrissky. I can't add another column into the table, however,
> > since it would be plotted in my chart as another series.
> > I'm looking for some way how to use the LineChart or AreaChart without
> > having to use a string-type column for x-asis. Or maybe a method of
> > DataTable or DataView to sort string column by numeric indexes.
> >
> > kukacz
> >
> > On Sun, Nov 28, 2010 at 2:16 AM, chrissky <[email protected]> wrote:
> > > Just add a numeric column to the table and copy the strings values by
> > > row. Then sort on that column.
> >
> > > On Nov 27, 5:41 pm, kukacz <[email protected]> wrote:
> > >> Hi,
> > >> I need to sort a datatable, where first column is of a string type. It
> > >> has to be a string since I'm creating a chart, where the first
> > >> column's data form a x-axis series. The problem is the actual data of
> > >> that column have numeric meaning.
> >
> > >> Still however, I wish to be able to resort the table dynamically while
> > >> keeping the correct numeric order of rows, not a string order. Is
> > >> there some way how to do this?
> >
> > >> Just to illustrate the unwanted behaviour, following column:
> > >> 512
> > >> 1024
> > >> 4096
> >
> > >> is being incorrectly resorted by string algorithm to:
> > >> 1024
> > >> 4097
> > >> 512
> >
> > >> Thank you.
> >
> > >> kukacz
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups "Google Visualization API" group.
> > > To post to this group, send email to
> [email protected].
> > > To unsubscribe from this group, send email to
> [email protected]<google-visualization-api%[email protected]>
> .
> > > For more options, visit this group athttp://
> groups.google.com/group/google-visualization-api?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-visualization-api%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-visualization-api?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to