Line Chart - $ Sign in X & Y Axis

6,726 views
Skip to first unread message

Swapnil Patil

unread,
Sep 24, 2011, 1:41:40 AM9/24/11
to Google Visualization API
How to show "$" Sign on X and Y Axis before values...???

Roni Biran

unread,
Sep 24, 2011, 4:00:27 AM9/24/11
to google-visua...@googlegroups.com
You write a function that goes over all datatable rows and set the column's value to be with $ sign



On Sep 24, 2011, at 8:41 AM, Swapnil Patil <swapnil...@gmail.com> wrote:

How to show "$" Sign on X and Y Axis before values...???

--
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.

ChartMan

unread,
Sep 24, 2011, 1:37:51 PM9/24/11
to google-visua...@googlegroups.com

Use formatted value and leave the value as it is.

ChartMan

asgallant

unread,
Sep 26, 2011, 8:47:33 AM9/26/11
to google-visua...@googlegroups.com
To format the axes, set the h/vAxis.format property of the options:

hAxis: {format: '$#,###'}
vAxis: {format: '$#,###'}

Format takes an ICU pattern set to format the values (this is different from data formatting using DataTable#NumberFormat method).

Swapnil Patil

unread,
Sep 27, 2011, 3:25:43 AM9/27/11
to Google Visualization API
var formatter = new google.visualization.NumberFormat(
{ prefix: '$'}
);
formatter.format(data, 1);

Thanks everyone.
Used this to format the values. But this only displays $ sign in tool
tip only and not on X Axis and Y axis labels.

On Sep 26, 5:47 pm, asgallant <drew_gall...@abtassoc.com> wrote:
> To format the axes, set the h/vAxis.format property of the options:
>
> hAxis: {format: '$#,###'}
> vAxis: {format: '$#,###'}
>
> Format takes an ICU pattern set<http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details>to format the values (this is different from
> *data* formatting using DataTable#NumberFormat method).

asgallant

unread,
Sep 27, 2011, 9:33:23 AM9/27/11
to google-visua...@googlegroups.com
Use the h/vAxis format options I listed to format the axes.

Swapnil Patil

unread,
Sep 28, 2011, 6:54:40 AM9/28/11
to Google Visualization API
Thanks asgallant !!!!

var formatter = new google.visualization.NumberFormat(
{ prefix: '$'}
);
formatter.format(data, 1);

and

hAxis: {format: '$#,###'}
vAxis: {format: '$#,###'}
acts one and the same. Both shows tooltip value formatted with $ sign
but $ sign doesn't appears on Y Axis labels.

asgallant

unread,
Sep 28, 2011, 8:42:04 AM9/28/11
to google-visua...@googlegroups.com
What kind of chart are you using?  Typically, one axis is a category axis, and will use whatever you put in column 0 as the axis values.  Since the category column is required to be a string, you'll have to add the $ yourself to each one, if that's what you are looking for.

Swapnil Patil

unread,
Sep 28, 2011, 9:53:40 AM9/28/11
to Google Visualization API
Dear asgallant, here is the source elements.

here the data table columns containing cuYear and pastyr with money
values.
Objective is to custom format the tooltip text and show Y Axis Lables
with cuYear values with the $ sign.
Hope it helps to understand the objective.

google.load('visualization', '1', { packages: ['corechart'] });

var data = new google.visualization.DataTable();
data.addColumn('string', 'x');
data.addColumn('number', cuYear);
data.addColumn('number', pastyr);

var formatter = new google.visualization.NumberFormat(
{ prefix: '$'}
);
formatter.format(data, 1);
formatter.format(data, 2);

new
google.visualization.LineChart(document.getElementById('visualization')).
draw(data,
{
curveType: "none",
titlePosition: 'out',
chartArea: { left: 70, top: 30 },
hAxis: { slantedText: false, textStyle: { color:
'#94511A', fontName: 'Arial,Helvetica,sans-serif', fontSize: 11} },
vAxis: { textStyle: { color: '#94511A', fontName:
'Arial,Helvetica,sans-serif', fontSize: 11 }, minValue: 0 },
width: 715,
height: 270,
legend: 'right',
pointSize: 3,
backgroundColor: '#FFFDEC',
legendBackgroundColor: "#FFFBD0",
legendHeight: 375,
legendTextStyle: { color: '#94511A', fontName:
'Arial', fontSize: 10 },
title: 'Title',
titleColor: "#94511A",
titleTextStyle: { color: '#94511A', fontName:
'Arial,Helvetica,sans-serif', fontSize: 11 }
});
}

asgallant

unread,
Sep 28, 2011, 11:33:04 AM9/28/11
to google-visua...@googlegroups.com
If you add:

format"$#,###"

to the vAxis option, it should be putting $'s on the Y axis.  It doesn't do anything with the tooltips.

Swapnil Patil

unread,
Sep 29, 2011, 2:34:08 AM9/29/11
to Google Visualization API
Dear asgallant ....!! Thank you very much.

This works....i had tried this 2-3 times after your reply but wasn't
working. But rechecked today n it works.
Many thanks.
Can you please take a look at this discussion.
http://groups.google.com/group/google-visualization-api/browse_thread/thread/db63744f7d0b6379

Ravish Kumar

unread,
Apr 6, 2015, 6:46:39 AM4/6/15
to google-visua...@googlegroups.com
But this is not working when i am using behind code
 

Reshma

unread,
Feb 13, 2018, 1:26:28 AM2/13/18
to Google Visualization API
Is there a way to add $ prefix with format : 'short' on X?

Yishai Levenglick

unread,
Mar 20, 2019, 7:15:20 AM3/20/19
to Google Visualization API
This is my hope to find for today

looking through the web, I found this answer but it's not very satisfactory especially for the React wrapper
Reply all
Reply to author
Forward
0 new messages