Sangeetha ilango
Sangeetha ilango

Reputation: 21

How to change the tick labels from decimals to integer in ContEx library?

Hello fellow learners.

I am creating charts in my Elixir project, using a Elixir library ContEx - https://hexdocs.pm/contex/Contex.html

I have a barchart. Below is the code i have used to create this chart.

    dataset = [
      ["Sage", scores.sage],
      ["Scientist", scores.scientist],
      ["Leader", scores.leader],
      ["Warrior", scores.warrior],
      ["Mother", scores.mother],
      ["Entrepreneur", scores.entrepreneur],
      ["Perfectionist", scores.perfectionist],
      ["Servant", scores.servant]
    ]

    options = [
      custom_value_scale:
        Contex.ContinuousLinearScale.new()
          |> Contex.ContinuousLinearScale.domain(0, 56)
          |> Contex.Scale.set_range(0, 56),
      colour_palette: ["ffdfae"],
      data_labels: false,
    ]


    Contex.Dataset.new(dataset)
    |> Contex.Plot.new(Contex.BarChart, 550, 280, options)
    |> Contex.Plot.to_svg()
    |> elem(1)

Now how should i change the y axis decimal ticks to integer. I have found the below function. But this doesn't seem to provide the answer that i want.

https://hexdocs.pm/contex/Contex.BarChart.html#custom_value_formatter/2

Is this the function that i need to use? I didn't find any other methods which will do this. Please help me to solve this.

How should i change the y axis ticks to integer?

Upvotes: 2

Views: 49

Answers (1)

Peaceful James
Peaceful James

Reputation: 2233

I do not think this is possible. The ContinuousLinearScale has floats "baked in" to the source code. You could copy the code from this module (in deps/contex/lib/chart/scale/continuous_linear_scale.ex) and make your own module that uses integers, e.g. DiscreteLinearScale. I have not read the whole module so I do not know how difficult it would be. To start, just find all floats and change them to integers. That might be enough to make it work.

Upvotes: 2

Related Questions