Area and scatter chart on a single graph

1,518 views
Skip to first unread message

cd2012

unread,
Mar 28, 2012, 11:45:30 AM3/28/12
to Google Visualization API
I need to plot an area chart and a scatter chart on the single graph.
Each chart will have its own axes. Is there any support for this in
the Google Visualization API?

asgallant

unread,
Mar 28, 2012, 2:08:30 PM3/28/12
to google-visua...@googlegroups.com
I'm afraid that this is not (yet?) possible.  Using the ScatterCharts, you can have some series represented by lines (not areas), but they don't support multiple vertical axes.  Area charts do support multiple veritical axes, but there is no way to combine them with ScatterCharts as of yet.  ComboCharts have started us down this road, though, so hopefully this will be available at some point in the future.

Jinji

unread,
Mar 29, 2012, 9:16:14 AM3/29/12
to google-visua...@googlegroups.com
Mixing ScatterChart and AreaChart isn't currently possible, and also isn't planed, and I want to take this opportunity to explain the rationale behind it.

Area/Line/Column/Bar/SteppedArea/Candlestick charts are all "function charts". "Function" as in "mathematical function" - something that maps values from some domain to target values. The domain can be either discrete or continuous, and each domain value has exactly one target value (or null). Each function chart can have multiple series, where each series is a single mathematical function, configured by the series option, and all series in the chart share the same domain. ComboChart is a function chart where each series can be of different type, from the above types (yes, all of the above types, the docs are out-dated).

ScatterChart, on the other hand, is not a function chart. Each "domain" value can have multiple "target" values, even within the same series (and therefor the terms "domain" and "target" aren't really accurate for scatter chart). That's why scatter chart and function charts don't mix, at least not easily.

That said, you can try a ComboChart with 2 series, one of them configured with {type: 'area'} and the other configured with {type: 'line', lineWidth: 0, pointSize: 7}. This might be good enough for you.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/MhNys9U3NMMJ.
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.

cd2012

unread,
Mar 29, 2012, 9:55:34 AM3/29/12
to Google Visualization API
Thanks. Those responses were very helpful.
To give you some insight of what I'm trying to do.. I'm plotting an
area chart that defines the good region in my graph. And then I need
to trace points that fall inside/outside the good region which will
end up becoming a scatter chart. That is where combining the two is
needed for my purposes.

I do think that your suggestion on using area+line as a ComboChart
might work for me, so I will certainly give that a try.

Thanks!

On Mar 29, 9:16 am, Jinji <ji...@google.com> wrote:
> Mixing ScatterChart and AreaChart isn't currently possible, and also isn't
> planed, and I want to take this opportunity to explain the rationale behind
> it.
>
> Area/Line/Column/Bar/SteppedArea/Candlestick charts are all "function
> charts". "Function" as in "mathematical function" - something that maps
> values from some domain to target values. The domain can be either discrete
> or continuous<http://code.google.com/apis/chart/interactive/docs/customizing_axes.h...>,
> and each domain value has exactly one target value (or null). Each function
> chart can have multiple series, where each series is a single mathematical
> function, configured by the series option, and all series in the chart
> share the same domain. ComboChart is a function chart where each series can
> be of different type, from the above types (yes, all of the above types,
> the docs are out-dated).
>
> ScatterChart, on the other hand, is not a function chart. Each "domain"
> value can have multiple "target" values, even within the same series (and
> therefor the terms "domain" and "target" aren't really accurate for scatter
> chart). That's why scatter chart and function charts don't mix, at least
> not easily.
>
> That said, you can try a ComboChart with 2 series, one of them configured
> with {type: 'area'} and the other configured with {type: 'line', lineWidth:
> 0, pointSize: 7}. This might be good enough for you.
>

asgallant

unread,
Mar 29, 2012, 11:06:23 AM3/29/12
to google-visua...@googlegroups.com
Y'know, I hadn't thought of that, but I suppose its a pretty good reason.  How would the Bar charts work with the others in a combo, though, given that they work on a different axis?

Jinji

unread,
Mar 29, 2012, 11:30:33 AM3/29/12
to google-visua...@googlegroups.com
Ah, yes. When I said "ComboChart supports all of the above types" I forgot bar chart is also on that list :) By "all" I meant "including stepped-area and candlestick". Anyway, column chart is supported, and that's what makes sense.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

asgallant

unread,
Jun 12, 2012, 11:38:29 AM6/12/12
to google-visua...@googlegroups.com
D'oh!  I answered the other thread a bit too soon >;o)

Now I remember this one.  You need to fix two things in your code:

1) You need a fifth column of data in your dataTable, as the candlesticks use 4 columns.
2) The series are zero-indexed, so there is no series "2" if you want one candlestick series and one line series.

Your code might look like this when done:

function drawVisualization({
    // Populate the data table.
    var dataTable google.visualization.arrayToDataTable([
        ['Mon'2028384530],
        ['Tue'3138556650],
        ['Wed'5055778045],
        ['Thu'7777665065],
        ['Fri'6866221580]
    // Treat first row as data as well.
    ]true);

    // Draw the chart.
    var chart new google.visualization.ComboChart(document.getElementById('visualization'));
    chart.draw(dataTable{
        legend:'none',
        width:600,
        height:400,
        seriesType'candlesticks',
        series{
            1{
                type'line'
            }
        }
    });
}

On Tuesday, June 12, 2012 6:30:28 AM UTC-4, mallaravi wrote:
Hi...
   I tried creating line chart on candle stick chart.. in combo chart.. i have coded as given below.. but the output coming is only candlestick chart ...it is ignoring line chart series.. please help me to draw line chart on candle stick.. chart...

      function drawVisualization({
        // Create and populate the data table.
        var data google.visualization.arrayToDataTable([
                ['Mon'20283845],
                ['Tue'31385566],
                ['Wed'50557780],
                ['Thu'77776650],
                ['Fri'68662215],       
                ['Sat'68662215],       
                ['Sun'69692918]       
        ]true);
      
        // Create and draw the visualization.
        var ac new google.visualization.ComboChart(document.getElementById('visualization'));
        ac.draw(data{
          title 'Monthly Coffee Production by Country',
          width600,
          height400,
          seriesType"candlesticks",
          series{2{type"line"}}
        });
      }
      google.setOnLoadCallback(drawVisualization); 

Thanks and Regards,
Ravi Kumar Malla
To post to this group, send email to google-visualization-api@googlegroups.com.
To unsubscribe from this group, send email to google-visualization-api+unsub...@googlegroups.com.

mallaravi

unread,
Jun 12, 2012, 11:56:53 AM6/12/12
to google-visua...@googlegroups.com
Hi Asgallant,
   Thanks a lot for the reply.. it worked :)...Thanks a ton again... Nice replies.. ":)..

Thanks and Regards,
Ravi Kumar Malla

asgallant

unread,
Aug 7, 2012, 10:13:59 AM8/7/12
to google-visua...@googlegroups.com
If you want to display only points, then you have two options:

1) use a LineChart and set the "lineWidth" option to 0 and the "pointSize" option to something larger than 0.
2) use a ScatterChart instead of a LineChart

On Tuesday, August 7, 2012 3:58:36 AM UTC-4, Lei WANG wrote:
gonna need a slight alter version of Line charts:
1.just print the point when there exits one ,don't  print anything if the corresponding data is null or "".
2. don't plot lines which connects these printed points


在 2012年3月29日星期四UTC+8下午9时16分14秒,Yuval Ronen写道:
To post to this group, send email to google-visualization-api@googlegroups.com.
To unsubscribe from this group, send email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages