hey all - is it not possible to generate a `vLine`...
# datascience
j
hey all - is it not possible to generate a
vLine
in a Kandy plot if the x axis isn't a number? I'm trying to plot something with Dates on the x axis and I want to place a vertical line on a specific date value. The plot always fails with exception
java.lang.IllegalArgumentException: Figure spec kind is not defined.
Here is a example to illustrate the problem:
Copy code
dataFrameOf(
    "foo" to  listOf("a", "b", "c"),
    "bar" to listOf(1, 2, 3)
)
    .plot {
        line {
            x("foo")
            y("bar")
        }
        vLine {
            xIntercept.constant("b")
        }
    }
This doesn't work. But this does:
Copy code
dataFrameOf(
    "foo" to  listOf("a", "b", "c"),
    "bar" to listOf(1, 2, 3)
)
    .plot {
        line {
            x("bar")
            y("foo")
        }
        vLine {
            xIntercept.constant(2)
        }
    }
Is this just a limitation with the Kandy library right now? Is there any ways around it?
👍 1
I thought maybe the issue was
String
isn't
Comparable
so I converted the dates into
LocalDate
instances, but the same error gets thrown still. It seems like
xIntercept.constant
only accepts numbers as input 🤔
a
Hi! Yep, coordinate settings only accepts
Number
- it’s a Lets-Plot limitation. In your case it will be enough to make mapping to a list of one element instead of constant setting:
Copy code
dataFrameOf(
    "foo" to  listOf("a", "b", "c"),
    "bar" to listOf(1, 2, 3)
)
    .plot {
        line {
            x("foo")
            y("bar")
        }
        vLine {
            xIntercept(listOf("b"))
        }
    }
j
ah ok. That's unfortunate but I'll try this workaround you suggest. Thanks for your help!
that worked! thank you
Copy code
allChanges.groupBy("Symbol")
    .plot {
        line {
            x("Date")
            y("Change (%)")
            color("Symbol")
        }
        vLine {
            xIntercept(listOf("10/19/2023"))
            type = LineType.DASHED
        }
    }
🔥 1