Coder Social home page Coder Social logo

tooltip title formatter about g2 HOT 7 CLOSED

antvis avatar antvis commented on May 4, 2024
tooltip title formatter

from g2.

Comments (7)

simaQ avatar simaQ commented on May 4, 2024 1

hi, you can declare formatter callback function for your tooltip title's data attribute, as follows:

chart.source(data,{ // 列定义
  'type': {
    // this will affect legend、tooltip and axis.
    formatter: function (value) {
      if (value == 1) {
        return '警告';
      }
      return '错误';
    }
  }
});

from g2.

maplor avatar maplor commented on May 4, 2024 1

the scale formatter will affect legend, tooltip and axis. It can't only format the tooltip or calculate with other field data。

In G2 4.x,TooltipCfg.title set a string will make some format but not flexible, I hope a function type so.

from g2.

StevenMasini avatar StevenMasini commented on May 4, 2024

Hi simaQ,

Thank you for your reply.

I tried to integrate the piece of code you gave me, but still it doesn't work. If I put a console.log within the callback function, it's never called.

from g2.

StevenMasini avatar StevenMasini commented on May 4, 2024

Oh okay my bad. I didn't understand that here 'type' actually means the axis name.
In my dataset my axis were named 'x' and 'y'.

Everything is working perfectly, thank you very much. :-)

from g2.

solovieff avatar solovieff commented on May 4, 2024

Now this prop is removed in v2, correct? How can I achieve the same behaviour?

from g2.

visiky avatar visiky commented on May 4, 2024
chart.scale('type', {
    // this will affect legend、tooltip and axis.
    formatter: function (value) {
      if (value == 1) {
        return '警告';
      }
      return '错误';
    }
});

from g2.

solovieff avatar solovieff commented on May 4, 2024

@Me-Momo sorry, it seems that I am talking about g2plot, which is a higher abstraction level of g2, correct?

Anyway, this behaviour does not allow you to have one axis values to be dependent on the others, I mean:

chart.scale('type', {
    // this will affect legend、tooltip and axis.
   // I can't do smth like: (value == 1 && date == X), due to I do not have date value
    formatter: function (value) {
      if (value == 1) {
        return '警告';
      }
      return '错误';
    }
});

Thanks!

from g2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.