antvG2 设置base对数 不对

antv G2 设置base不正确,占用大家的一点时间帮忙看看吧

img

    contain() {
      const chart = new Chart({ container: 'container',theme: 'classic', autoFit: true});

      chart.data({
        type: 'inline',
        value: [
          [5,0.09459459], [10,0.22972973],
          [15,0.36486486], [20,0.5],
          [25,0.63513514], [30,0.77027027],
          [35,0.90540541]
        ],

      });
      chart
          .point()
          .encode('x', (d) => d[0])
          .encode('y', (d) => d[1])
          .encode('shape', 'point')
          .scale('x', {
            domain: [1, 100],
             type: 'log',
              // base: 10,
            //tickCount:3,
         },
    )
          .scale('y', {
            domain: [0.001, 1],
             type: 'log',
            base: 10,
            //tickCount:4,
           })
          .style('fillOpacity', 0.75)
          .axis('x',
              {
                tickLine: {
                  lineWidth: 2,
                  length: 10,
                  stroke: 'red',
                  alignWithLabel:true,
                }
              }
          )
      // chart
      //     .interval().
      //      axis('x', { tickCount: 4 })
      chart
          .line()
          .data({
            transform: [
              {
                type: 'custom',
                callback: regressionExp(),
              },
            ],
          })

          .encode('x', (d) => d[0])
          .encode('y', (d) => d[1])
          .encode('shape', 'smooth')
          .style('stroke', '#30BF78')
          .style('lineWidth', 2)

      chart.render();

    },


已解决


          .scale('x', { domain: [1, 100], type: 'log' })
          .scale('y', { domain: [0.001, 1], type: 'log' })
          .axis('y', { tickCount: -1})
          .axis('x', { tickCount: -1})
不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 以下回答来自chatgpt: 回答: 可以通过以下步骤来设置base对数: 1. 在G2中创建一个chart对象: ```javascript var chart = new G2.Chart({ container: 'c1', forceFit: true }); ``` 2. 加载数据: ```javascript chart.source(data); ``` 3. 创建横轴和纵轴: ```javascript chart.axis('xAxis', { title: { text: 'X 轴' } }); chart.axis('yAxis', { title: { text: 'Y 轴' }, labelFormatter: function labelFormatter(val) { return val.toFixed(1); // 保留一位小数 } }); ``` 4. 设置base对数: ```javascript chart.scale('yAxis', { type: 'pow', exponent: 10, base: 2 // 设置base对数为2 }); ``` 完整代码示例: ```javascript var data = [ { x: 0, y: 1 }, { x: 1, y: 3 }, { x: 2, y: 8 }, { x: 3, y: 20 }, { x: 4, y: 50 }, { x: 5, y: 125 }, { x: 6, y: 315 } ]; var chart = new G2.Chart({ container: 'c1', forceFit: true }); chart.source(data); chart.axis('xAxis', { title: { text: 'X 轴' } }); chart.axis('yAxis', { title: { text: 'Y 轴' }, labelFormatter: function labelFormatter(val) { return val.toFixed(1); // 保留一位小数 } }); chart.scale('yAxis', { type: 'pow', exponent: 10, base: 2 // 设置base对数为2 }); chart.line().position('x*y').color('#1890ff').size(2); chart.render(); ``` 最终效果可以参考以下图片: ![G2 with logarithmic scale](https://gw.alipayobjects.com/zos/rmsportal/LRIahzQeqdcPUmSkYYEW.png)

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^