Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Build an ExtJS 3.4 Scatter Chart with Logarithmic Axis

DZone's Guide to

How to Build an ExtJS 3.4 Scatter Chart with Logarithmic Axis

· Big Data Zone
Free Resource

Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brought to you in partnership with Hortonworks.

Problem

You're rendering data that increases exponentially, and wish to display a chart with a log-scale axis.

Exponential data:

Logarithmic scale rendering of the same:

Solution

Set the “scale” property of the relevant axis to “logarithmic.”

Discussion

There does not seem to be any way to control the frequency of the major/minor tick marks other than by fixed intervals. Be careful about setting these in this chart type, as you can quickly overwhelm the browser to the point where Flash is unresponsive. It may be preferable to control the rendering using tooltips on the data points.

For further discussion of similar charts, see the ExtJS scatter chartexample and ExtJS trend line example.

Ext.onReady(function() {
Ext.chart.Chart.CHART_URL = 'ext-3.4.0/resources/charts.swf';
   var store = new Ext.data.JsonStore({
    fields: ['year', 'action'],
    data: [
        {year: 2005, action: 100000},
        {year: 2006, action: 1000000},
        {year: 2007, action: 10000000},
        {year: 2008, action: 100000000}
        ]
  });
 
  new Ext.Panel({
    width: 390,
    height: 300,
    renderTo: 'container',
    title: 'Scatter Plot - Takings by Genre',
    items: {
      xtype: 'linechart',
      store: store,
      xField: 'year',
      xAxis: new Ext.chart.NumericAxis({
        minimum: 2004,
        maximum: 2009,
        majorUnit: 1,
 
      }),
      yAxis: new Ext.chart.NumericAxis({
        labelRenderer: Ext.util.Format.usMoney,
        minimum: 10,
        maximum: 1000000000,
        scale: 'logarithmic'
      }),
      series: [{
        yField: 'action',
        displayName: 'Action',
        style: {
          lineAlpha: 0.0
        }
      }]
    }
  });
});


Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

Topics:

Published at DZone with permission of Gary Sieling, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}