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

Bar Chart with Step Chart #566

Closed
SamMorrowDrums opened this issue Sep 17, 2014 · 12 comments
Closed

Bar Chart with Step Chart #566

SamMorrowDrums opened this issue Sep 17, 2014 · 12 comments
Labels
C-feature-request Category: A feature request or an enhancement resolved maybe

Comments

@SamMorrowDrums
Copy link

Aligning the steps with the centre of the bar does not really work as a chart.

If it is possible instead to have an option where the steps are flat above bars, and change value in between bars this would be much more effective.

This is only an issue when combining step charts with bar charts.

@SamMorrowDrums
Copy link
Author

Screenshot to highlight the issue:

image

@SamMorrowDrums
Copy link
Author

It would be absolutely amazing if there was a way to make a type of step, that lined up above bars, rather than changing value in the middle of them. I hope it's not too specific a request.

@OrphicAbyss
Copy link

Here is an example interpolate function to create a bar centered step graph:

var line = d3.svg.line()
    .interpolate(function(points) {
        // halfStep needs to be half of the step size of the categories
        var out = "", halfStep = x(1)/2;
        out += points[0][0] - halfStep + " " + points[0][1];
        points.shift();
        points.forEach(function (point) {
            out += 'H' + (point[0] - halfStep) + 'V' + point[1] + 'H' + (point[0] + halfStep);
        });
        return out;
    })
    .x(function(d) { return x(d.x); })
    .y(function(d) { return y(d.y); });

@nimasmi
Copy link

nimasmi commented Sep 25, 2014

This is only an issue when combining step charts with bar charts.

It is also an issue for a vanilla step chart. With the current implementation, the final data point is not represented by anything tangible, as in this chart:

screen shot 2014-09-25 at 11 31 13

The intent is to represent a value for the duration of a week, but the final week's green value (0.14) here is represented by a vertical line only, and the orange value is almost impossible to see.

@masayuki0812
Copy link
Member

Hi, I agree to modify step chart interpolation as you suggested. Now step chart uses step interpolation type (before this fix, it was step-after), so step chart will change its line on the tick point (before this fix, it was on the data point).

And I introduced line_step_type so that we can specify step interpolation type. So if you want to use step-after, which is the previous default, please specify this option as step-after.

Could you try the latest code? Thanks.

@masayuki0812 masayuki0812 added C-feature-request Category: A feature request or an enhancement resolved maybe labels Oct 8, 2014
@nimasmi
Copy link

nimasmi commented Oct 13, 2014

Thanks for this change. It addresses the alignment issue, but introduces a new problem in my use case at least.

Before

c3_before

  • Bars are not centred over labels.
  • Five labels, but only four full-width bars.
  • Fifth bar is shown as a thin line for its left-hand edge only.

After

c3_after

  • Bars are centred over labels ✓
  • All five bars represented ✓
  • First and last bars are shown only half-width (so the width of all five bars is the same as the width of four bars in the 'before' picture). This is still an improvement, at least.

@masayuki0812
Copy link
Member

I think 3rd issue has been fixed now. Only when category axis, the edges of step chart will be shown. Could you try the latest version again? Thanks.

@nimasmi
Copy link

nimasmi commented Oct 31, 2014

This is great. Before:
screen shot 2014-10-31 at 16 08 57

After:
screen shot 2014-10-31 at 16 07 44

Thanks very much for the fix.

@nimasmi
Copy link

nimasmi commented Oct 31, 2014

PS the improvement from 6bebdb2 is also noticeable.

@masayuki0812
Copy link
Member

Thank you for your confirming. Then, please let me close this issue.

@Mantish
Copy link

Mantish commented May 10, 2017

Hi
This is working fine for regular charts, but when the axis is rotated (like in the first screenshot), it doesn't look good.
This is due to the step interpolation that works in a "horizontal" way.
...I think I can provide a PR, if you agree this is something that needs to be fixed

@amran-mamoon-fn
Copy link

amran-mamoon-fn commented Sep 27, 2017

For a single data point, it's showing nothing. Is there any way to show a vertical line for a single data point?

var chart = c3.generate({
    data: {
        columns: [
            ['data1', 300]
        ],
        types: {
            data1: 'step'
        }
    },
    line: {
        step: {
            type: 'step-after'
        }
     }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request or an enhancement resolved maybe
Projects
None yet
Development

No branches or pull requests

6 participants