1

I'm needing to create a gauge graph in r, but I can't make the "axisLine" function in gradient colors.

library(echarts4r)
gauge_x <- e_charts() %>%
e_gauge(800, 
      "Incerteza TC",
      startAngle = 180,
      endAngle = 0,
      min = 0,
      max = 1000,
      splitNumber = 5,
      radius = "185",
      itemStyle = list(color = "#000000"),
      #axisLine = list(lineStyle = list(color = list(type = "radial", x = "0.5", y = "0.5", r = "0.5",
                                                    #backgroundColor = radial_gradient))),
      axisTick = list(lineStyle = list(width = 2, color = "#000000")),
      splitLine = list(lineStyle = list(color = "#000000", type = "solid")),
      axisLabel = list(show = TRUE, color = "#000000", fontWeight = "bold", borderRadius = 5),
      pointer = list(show = TRUE, icon = "triangle", length = "80%"), itemStyle = list(color = "black"),
      detail = list(show = TRUE, color = "#000000"),
      title = list(show = TRUE, fontWeight = "bolder"))
print(gauge_x)



      
Quinten
  • 35,235
  • 5
  • 20
  • 53

1 Answers1

0

As I am seeing in the documentation, you can not specify gradient color or any pattern fill for axisLine color in the gauge chart. You can only specify an array of colors for segments. As per the documentation,

The axis line of gauge chart can be divided to several segments in different colors. The end position and color of each segment can be expressed by an array.

So you can only color the axisLine by specifying a list of vectors containing the percentages and corresponding colors in the following way :

library(echarts4r)
library(magrittr)


e_charts() %>%
    e_gauge(
        800,
        "Incerteza TC",
        startAngle = 180,
        endAngle = 0,
        min = 0,
        max = 1000,
        splitNumber = 5,
        radius = "185",
        itemStyle = list(color = "#000000"),
        axisLine = list(lineStyle = list(
            color = list(c(0.33, "red"), c(0.67, "blue"), c(1, "green"))
        )),
        axisTick = list(lineStyle = list(width = 2, color = "#000000")),
        splitLine = list(lineStyle = list(color = "#000000", type = "solid")),
        axisLabel = list(
            show = TRUE,
            color = "#000000",
            fontWeight = "bold",
            borderRadius = 5
        ),
        pointer = list(show = TRUE, icon = "triangle", length = "80%"),
        itemStyle = list(color = "black"),
        detail = list(show = TRUE, color = "#000000"),
        title = list(show = TRUE, fontWeight = "bolder")
    )

echarts gauge chart with axsiLine colored

Hope this helps!

shafee
  • 15,566
  • 3
  • 19
  • 47