How do I do this.....?

38 views
Skip to first unread message

NP

unread,
Oct 25, 2011, 8:51:13 PM10/25/11
to Google Visualization API
I have a 2 column table with column headers Object, Count.

I have data given as (A, 2), (A, 5), (B,4), (C,3). A, B, C are the
objects and the other values are the count

In the graph, the objects are the X-axis and the count is the Y-axis.

How do I plot a line graph so that object 'A' appears only once on the
X-axis but it will show the points for both counts 2 & 5?

Right now, when I plot the graph, object 'A' appears twice on the
graph - one for each of 2 and 5.

If I can't do this with a line graph, which other type of graph can I
use? Basically I want to have a graph which will show distinct objects
on the X-axis and the different counts encountered for the objects on
the Y-axis and it is possible that an object might have different
counts.

Thanks...

Radhouene Gniwa

unread,
Oct 26, 2011, 3:53:28 AM10/26/11
to google-visua...@googlegroups.com
To be able to do that The first column should be a number. With strings, the chart renders with each row having its own axis tick.  With numbers, it renders the chart in coordinate grid system, which is what you need to do.You need also to set the 'strictFirstColumnType' option to true to make this work:



2011/10/26 NP <neara...@gmail.com>

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


asgallant

unread,
Oct 26, 2011, 10:26:52 AM10/26/11
to google-visua...@googlegroups.com
This technically works with that method, but it requires your axis values to be numbers, and it sounds like you want the object names.  Do you care about having lines or multiple colors?  If a series of points of the same color for all data points will do, you can arrange your data such that you have 1 column of object names plus a number of columns equal to the maximum number of counts per object.  For example, given this data:

Object | Count
--------------
  A    |   3
  A    |   5
  A    |   9
  A    |   11
  B    |   1
  B    |   4
  B    |   6
  C    |   3
  C    |   7
  C    |   10
  C    |   12
  C    |   14

You would create the chart like this: http://jsfiddle.net/uKytR/1/

The options set all colors the same (you need one entry in the 'colors' array for each column), as you would have multiple colors per object otherwise; remove the lines, as they would go from A -> B -> C, rather than A -> A -> A; increase the point size so individual points become visible; and remove every series except the first one from the legend so you don't end up with 5 entries called 'Count'.


NP

unread,
Oct 26, 2011, 1:17:09 PM10/26/11
to Google Visualization API
Thanks for this.

You said..
**** Do you care about having lines or multiple colors ****

I care about having a line, not necessarily about color. Is there a
way I can have a line joining all the points?



On Oct 26, 7:26 am, asgallant <drew_gall...@abtassoc.com> wrote:
> This *technically* works with that method, but it requires your axis values

asgallant

unread,
Oct 26, 2011, 2:24:17 PM10/26/11
to google-visua...@googlegroups.com
Joining the points vertically?  Not if you want your object names for axis labels.  If you are willing to forego axis labels entirely (using the legend instead), then you can do so: http://jsfiddle.net/uKytR/1/

NP

unread,
Oct 27, 2011, 1:02:04 AM10/27/11
to Google Visualization API
sorry, this is the same link as the example you pasted for me before.

asgallant

unread,
Oct 27, 2011, 8:52:55 AM10/27/11
to google-visua...@googlegroups.com
Oops, I guess I didn't save those changes >;o)  Let's try this again: http://jsfiddle.net/uKytR/2/

NP

unread,
Oct 29, 2011, 2:43:24 PM10/29/11
to Google Visualization API
Thanks for this. Both you and asgallant have given me some ideas that
I can play around with.
I noticed that when I set the first column to a number, the graph now
displays as a grid and the grids are visible in the chart area. Is
there any way I can prevent the grids from showing
within the chart area? i.e. I want to show the horizontal and vertical
axis with the points in the graph but not the vertical and horizontal
lines showing the intersections

On Oct 26, 12:53 am, Radhouene Gniwa <radhouene.gn...@gmail.com>
wrote:
> To be able to do that The first column should be a number. With strings, the
> chart renders with each row having its own axis tick.  With numbers, it
> renders the chart in coordinate grid system, which is what you need to
> do.You need also to set the 'strictFirstColumnType' option to true to make
> this work:
>
> 2011/10/26 NP <nearapo...@gmail.com>

NP

unread,
Oct 29, 2011, 2:44:32 PM10/29/11
to Google Visualization API
Thanks

asgallant

unread,
Oct 31, 2011, 8:39:04 AM10/31/11
to google-visua...@googlegroups.com
The only option as far as the grid lines goes is the h/vAxis.gridlineColor option, which you can set to match the background of the chart.
Reply all
Reply to author
Forward
0 new messages