Giter VIP home page Giter VIP logo

Comments (7)

leeoniya avatar leeoniya commented on May 25, 2024

take a look at the first two examples here: https://leeoniya.github.io/uPlot/demos/multi-bars.html

you can provide disp.fill and disp.stroke callbacks to the bars pathbuilder that can do per-bar coloring.

uPlot/demos/multi-bars.html

Lines 217 to 234 in e579947

disp: {
stroke: {
unit: 3,
values: (u, seriesIdx) => u.data[2].map(v =>
v == 0 ? "#33BB55" :
v == 1 ? "#F79420" :
"#BB1133"
),
},
fill: {
unit: 3,
values: (u, seriesIdx) => u.data[2].map(v =>
v == 0 ? "#33BB55A0" :
v == 1 ? "#F79420A0" :
"#BB1133A0"
),
}
}

from uplot.

H-For-Hitesh avatar H-For-Hitesh commented on May 25, 2024

Hi @leeoniya Thanks for the response. I understood the solution you suggested but it does not resolve the complete problem in my case. In this case I can render bar charts of different colour with different labels but I'm not able to select/deselect different colors in the metric legends(same goes for the demo which you have shared). Any solution on this is highly appreciated!

from uplot.

H-For-Hitesh avatar H-For-Hitesh commented on May 25, 2024

Added some images for your reference @leeoniya :)

image
when Legend Selected
image
when legend is not selected

from uplot.

leeoniya avatar leeoniya commented on May 25, 2024

uPlot's legend is series-based.

since there is only one series here, what you're looking for is a value-based legend. so probably you can make your own legend that would act as a data/value filter when clicked and use u.setData(filteredData) to update the plot with the "off" values removed. so, for example if you wanted to disable "Wed", you can have your custom legend filter out data at index [2].

this is a bit of an unusual requirement, i think. do you have examples of other chart libraries that do this?

for example, Chart.js legend is also series-based: https://www.chartjs.org/docs/latest/charts/bar.html
same with echarts: https://echarts.apache.org/examples/en/index.html#chart-type-bar
same with high charts: https://www.highcharts.com/demo/highcharts/bar-basic

from uplot.

H-For-Hitesh avatar H-For-Hitesh commented on May 25, 2024

Hi @leeoniya Thanks again for the response. I worked on the solution you suggested, this is working well. :)

from uplot.

H-For-Hitesh avatar H-For-Hitesh commented on May 25, 2024

Hi @leeoniya Regarding the same issue. Is there any way tooltip may work for similar bar chart. Checked the current tooltip plugin shared in demos. It works with series so there is single text for whole chart, Is there any way I can have a separate tooltip label for each bar?

from uplot.

leeoniya avatar leeoniya commented on May 25, 2024

the tooltip is not part of uPlot, so you can definitely make your own work however you need.

from uplot.

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.