question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

xaxis categories don't update with line chart (but do so with bar chart)

See original GitHub issue

I’m fetching data from an api that returns data for both the series and the x-axis categories properties. The api call and state updating is done within componentDidMount. This all works fine when the chart type is a bar chart, but the xaxis state won’t update when the chart type is changed to a line chart. Any help you could provide would be greatly appreciated. Thanks!

` import React, { Component } from ‘react’; import Chart from ‘react-apexcharts’;

class WAUchart extends Component { constructor(props) { super(props); this.state = { options: { chart: { id: “WAU” }, xaxis: { type: “category”, categories: [] }, title: { text: “WAU”, align: “center”, style: { fontSize: “20px”, color: “black” } }, labels: [] }, series: [ { name: “WAU”, data: [] } ], }; };

fetchData() {
    fetch('http://127.0.0.1:5000/wau?start_time="2018-05-01"')
        .then(response => response.json())
        .then(dat => {
            const newSeries = [];
            const newXaxis = JSON.parse(dat.xaxis);
            newSeries.push({ data: JSON.parse(dat.series), name: this.state.series[0].name });
            this.setState({
                series: newSeries,
                options: { ...this.state.options, labels: newXaxis, xaxis: { ...this.state.options.xaxis, categories: newXaxis } }
            });
            console.log(this.state.options);
        })
};

componentDidMount() {
    this.fetchData()
};

render() {
    return (
        <Chart
            options={this.state.options}
            series={this.state.series}
            type="line"
            height="450"
            width="100%"
        />
    )
}

}

export default WAUchart; ’

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
junedchhipacommented, Mar 11, 2019

I suspect this is a bug which is caused by the latest update. Can you try changing xaxis.tickPlacement: 'between'?

If the above change fixes the issue, I will be sure of the cause of this bug and will work on it.

2reactions
mkantz84commented, Oct 22, 2019

I’m facing the same issue, but using xaxis.tickPlacement: ‘between’ does not resolve the issue in my case… PR94

versions: “react-apexcharts”: “^1.3.3” “apexcharts”: “^3.8.6”

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChartJS, updating chart type does not update xAxis properly
In this example, I create the initial chart as a bar chart. I then change it to to line chart but the line...
Read more >
Change the display of chart axes - Microsoft Support
On a chart, click the horizontal (category) axis that you want to change, or do the following to select the axis from a...
Read more >
xAxis.categories | highcharts API Reference
If categories are present for the xAxis, names are used instead of numbers for that axis. Since Highcharts 3.0, categories can also be...
Read more >
Excel Chart not showing SOME X-axis labels - Super User
I think clicked "edit" on the Horizontal (category) Axis labels and confirmed it was the correct selection (in my case I had to...
Read more >
Data Visualization: Chart Dos and Don'ts - Duke Library Guides
Do : · Avoid distortion. For bar charts, the numerical axis (often the y axis) must start at zero. · Wide ranges: ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found