# GLMakie datainspector: Tooltip from x,y-coordinate to date, value

**URL:** <https://discourse.julialang.org/t/glmakie-datainspector-tooltip-from-x-y-coordinate-to-date-value/128241>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [April 20, 2025, 8:05am UTC](https://discourse.julialang.org/t/glmakie-datainspector-tooltip-from-x-y-coordinate-to-date-value/128241 "2025-04-20T08:05:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred\_van\_der\_Zeeuw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred_van_der_zeeuw/32/216423_2.png) [@Fred\_van\_der\_Zeeuw](https://discourse.julialang.org/u/Fred_van_der_Zeeuw)\
**Post date:** [April 20, 2025, 8:05am UTC](https://discourse.julialang.org/t/glmakie-datainspector-tooltip-from-x-y-coordinate-to-date-value/128241/1 "2025-04-20T08:05:09Z")

</div>

I am trying to plot a candlestick chart which can show tooltips with the date and open, high, low, close values but I am getting just x,y coordinates. I tried tooltip but didn’t get it to work. Tried datainspector which works but only shows x,y coordinates. Help is appreciated!

```julia
using GLMakie
using Dates
using Colors
using MarketData
using Statistics

# Theme and Color Setup
set_theme!(theme_light())
bullish_color = colorant"#009E73"
bearish_color = colorant"#D55E00"

# Load and Prepare Market Data
ohlc_data = ohlc
timestamps = timestamp(ohlc_data)
N = length(timestamps)
dates = collect(timestamps)

opens = values(ohlc_data.Open)
highs = values(ohlc_data.High)
lows = values(ohlc_data.Low)
closes = values(ohlc_data.Close)

# Candle body info
body_heights = abs.(closes .- opens)
body_offsets = min.(opens, closes)
colors = [c > o ? bullish_color : bearish_color for (o, c) in zip(opens, closes)]

# Plot Layout
fig = Figure(size = (1000, 500))
ax = Axis(fig[1, 1], title = "Candlestick Chart", ylabel = "Price")

for i in 1:length(timestamps)
    lines!(ax, [timestamps[i], timestamps[i]], [lows[i], highs[i]]; color = :black, linewidth = 1.0)
end
barplot!(ax, timestamps, body_heights; offset = body_offsets, color = colors, width = 0.6, strokecolor = :black, strokewidth = 0.5)

DataInspector(fig)
fig

```

Screenshot:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/3/83108d09b35b7b7b109ada6bee69ebea0b822ee2.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 20, 2025, 8:53am UTC](https://discourse.julialang.org/t/glmakie-datainspector-tooltip-from-x-y-coordinate-to-date-value/128241/2 "2025-04-20T08:53:37Z")

</div>

The docs say

> The displayed text can be adjusted by setting `plot.inspector_label` to a function `(plot, index, position) -> "my_label"` returning a label

So I would try adding such a function to barplot and lines, I would think the `index` is already corrected such that you can reference your data with it, but not sure, might also be a lower-level index from GLMakie in which case a transformation on that would be necessary.

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [April 20, 2025, 9:00am UTC](https://discourse.julialang.org/t/glmakie-datainspector-tooltip-from-x-y-coordinate-to-date-value/128241/3 "2025-04-20T09:00:36Z")

</div>

Hi, and welcome to the Julia community!

You simply need to tell the `DataInspector` what to do, via the argument `inspector_label` to `barplot!`.

Since I don’t have access to your `ohlc` and am not really sure how to randomly generate this, here’s an example of three named points, where hovering over them also shows the names. There are also line segments connecting the points, and hovering over those shows the relative weights of the endpoints.

```julia
using GLMakie

point_names = ["Amy", "Bob", "Carl"]
nb_points = length(point_names)
point_positions = rand(2, nb_points)

function point_inspector_label(plt, index, position)
    return "x: $(position[1])\ny: $(position[2])\nname: $(point_names[index])"
end

function line_inspector_label(plt, index, position)
    start_point_index = mod1(index - 1, nb_points)
    end_point_index = mod1(index, nb_points)
    fraction = first((position .- point_positions[:, start_point_index]) ./ (point_positions[:, end_point_index] - point_positions[:, start_point_index])) # Both components should be valid, unless we run into numerical problems
    return "$(fraction * 100)% $(point_names[end_point_index]), $((1 - fraction) * 100)% $(point_names[start_point_index])"
end

fig, ax, plt = scatter(point_positions, inspector_label = point_inspector_label)
lines!(ax, [point_positions point_positions[:, 1]], inspector_label = line_inspector_label)

DataInspector(fig)
display(fig)

```

 ![HoverPoint](https://global.discourse-cdn.com/julialang/original/3X/a/3/a35142d3665bdeb1c1da117a168702bf177fc549.png)  
 ![HoverLabel](https://global.discourse-cdn.com/julialang/original/3X/5/7/573edb4ef96e06956c40bf40196a0f544f1e3594.png)

---

<div class="post-metadata">

**Author:** ![Fred\_van\_der\_Zeeuw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred_van_der_zeeuw/32/216423_2.png) [@Fred\_van\_der\_Zeeuw](https://discourse.julialang.org/u/Fred_van_der_Zeeuw)\
**Post date:** [April 20, 2025, 9:58am UTC](https://discourse.julialang.org/t/glmakie-datainspector-tooltip-from-x-y-coordinate-to-date-value/128241/4 "2025-04-20T09:58:52Z")

</div>

Thanks for the help, exactly what I was looking for.

By the way, the OHLC data is included by code line `using MarketData`
