Dojo Axis Log Scale

I used a Dojo chart to create a column chart. So far I am very impressed with this, but decided that I need the logarithmic y axis. It doesn't seem like it is supported yet, although I saw a blog post meaning it was planned at some point.

Does anyone know that this is possible at the moment? If not, then I would love to try to write an improvement myself, so if anyone has any tips on where to start, they would be gratefully accepted. I suspect this is a case of implementing a new type of scale, although I have not yet spent much time searching for the source.

Thanks, Martin.

+3
source share
1 answer

dojox.gfx still does not have a logarithmic axis.

Update. One way to do this is to reassign the data along the logarithmic axis and use a linear axis with custom labels. For instance:

// we will transform our 'x' to a decadic logarithmic scale

var LOG10 = Math.log(10);

var data = [...]; // my data of {x, y}
var transformedData = dojo.map(data, function(value){
  return {
    x: Math.log(value.x) / LOG10,
    y: value.y // 'y' is unchanged
  };
});

// ...

// add the axis and the data
chart.addAxis("x", {
  natural: true,
  includeZero: true,
  // our logarithmic labels
  labels: [
    {value: 0, text: "1"},
    {value: 1, text: "10"},
    {value: 2, text: "100"},
    {value: 3, text: "1000"},
    {value: 4, text: "10^4"},
    {value: 5, text: "10^5"},
    {value: 6, text: "10^6"},
    {value: 7, text: "10^7"},
    {value: 8, text: "10^8"},
    {value: 9, text: "10^9"}
  ]
});
chart.addSeries("my data", transformedData);

// ...

Something like this will do the trick. Another option is to use the marking function to automatically generate “logarithmic” labels.

+3
source

Source: https://habr.com/ru/post/1728150/


All Articles