Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with negative values for barchart #95

Open
boon-wego opened this issue Apr 17, 2024 · 1 comment
Open

Problem with negative values for barchart #95

boon-wego opened this issue Apr 17, 2024 · 1 comment

Comments

@boon-wego
Copy link

I am having problem displaying barchart with negative values.

I tried to see if anyone has already reported this issue. But judging from #91 it seems negative values is supported all along.

I'm using Contex version 0.5.0

Code

data = [
      ["A", -10.0],
      ["B", 20.0],
      ["C", -50.0]
    ]

    dataset = Contex.Dataset.new(data, ["X", "Y"])

    options = [
      mapping: %{category_col: "X", value_cols: ["Y"]},
      type: :stacked,
      data_labels: true,
      orientation: :vertical
    ]

    chart =
      Contex.Plot.new(dataset, Contex.BarChart, 600, 400, options)
      |> Contex.Plot.titles("", "")
      |> Contex.Plot.axis_labels("", "")
      |> Contex.Plot.plot_options(%{})
      |> Contex.Plot.to_svg()

Result

Screenshot 2024-04-17 at 7 17 14 PM
@JoshAusHessen
Copy link

JoshAusHessen commented May 4, 2024

Hi,
you are using the type: :stacked. I think if you are using the type: :grouped your chart would look like the ones in issue #91

For stacked bar charts negative numbers would be more complicated.
I think currently stacked charts use deltas. so the second bar of the same category starts at the end of the first bar. If there would be something like :stacked_absolute that would

  • accept absolute values rather than deltas
  • draw all bars originating from 0 rather than the end of the last bar
  • draw the largest bar first so that smaller ones aren't completely hidden

one could display negative numbers similar to #91, but stacked.

I actually have a use case for that myself, I will give it a shot to implement that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants