0

I am creating a google scatter chart using google apps script EmbeddedChart Option. Below is the datatable that I want to assign to the chart. The first column goes to x axis labels and graph is getting generated for NPP and Noise values.

                 NPP        Noise  
-1.28,      -7.84625,        2.33           
-1.83,       -12.561,        4.55

I need to set the datalabels for each scatter point in the graph and its working with setting "datalabel" to "value". But my requirement is to display different text as data labels not the value. Like below, I have added a column datalabel and given the values for each point.

              NPP      Noise   DataLabel  
-1.28,  -7.84625,      2.33,      Spring        
-1.83,   -12.561,      4.55,   Hibernate  

Can I display this labels as datalabel on the scatter points?

Code:

var chart = NormalGraphSheet.newChart()
.setChartType(Charts.ChartType.SCATTER)
.setPosition(2, 1, 7, 6) .addRange(normalPlotCalculationsSheet.getRange(tableStartRow,2, noOfCols, 4))
.setOption('series', {0: {pointSize: 14, color: 'red'},1: {pointSize:0},2: {pointSize: 10, color: 'green'}})
.setOption('trendlines', {1: {type: 'linear',color:'blue',lineWidth:2,opacity:80}}).build(); NormalGraphSheet.insertChart(chart);
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Are you able to share the script and the chart you have generated that you have so far? – AL. Apr 15 '16 at 00:24
  • below is the code var chart = NormalGraphSheet.newChart() .setChartType(Charts.ChartType.SCATTER) .setPosition(2, 1, 7, 6) .addRange(normalPlotCalculationsSheet.getRange(tableStartRow,2, noOfCols, 4)) .setOption('series', {0: {pointSize: 14, color: 'red'},1: {pointSize:0},2: {pointSize: 10, color: 'green'}}) .setOption('trendlines', {1: {type: 'linear',color: 'blue',lineWidth:2,opacity:80}}) .build(); NormalGraphSheet.insertChart(chart); – Jyoti Pathak Apr 15 '16 at 05:23
  • Sorry, I'm getting confused, by *datalabel* do you mean *legend*? Can you also provide a screenshot of what you are getting right now and what you want to retrieve (edit via paint?)? – AL. Apr 15 '16 at 11:46
  • I need data Labels for scatter points in the chart. Not the legends. currently we can set data Labels to 'value'. but don't want to print value. Instead i want the data labels to display the value i provided in DataLabel Column(i.e spring,hibernate). – Jyoti Pathak Apr 15 '16 at 11:55

1 Answers1

0

Okay, so I googled and looked around the community for quite sometime, and managed to see this very similar post, only difference I can see is the data you guys use, the first top answer suggests just adding a Tool tip for each of the data points, which I'm guessing is not what you want.

The second top answer suggests using the Visualization API, which is the same as to this accepted answer from WebApps Community (with a similar concern), though the second answer seems to demonstrate that custom data labels are automatically included when formatted in a specific way:

  • First column: X axis
  • Second column: Y axis
  • Third column: Data label

When looked at in the customization tab via spreadsheets, the value of Data Label is shown as Custom though when trying to manually do a chart, and going to the Data Label drop-down again, it only shows None and Value. So I think, since you are doing the chart via the script, it better for you to use the Visualization API. Hope this helps you somehow. Good luck.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281