0

I create a multibar chart in python with python-nvd3.

The problem is that only every second X-Axis tick/label is showing up on the chart.

I generate is the chart in python before passing it through to a flask-template.

The problem is described in another SO posts too, but the solution is directed at Angular and does not point to a way that I can pass the attribute in python to the chart before I create it.


StackOverflow solution 1 here

StackOverflow solution 2 here


The solution suggests setting the attribute .reduceXTicks(true) but my problem is that I can't see a way to set this custom attribute in python.

This is what the chart looks like.

enter image description here

This is how I generate the chart, and also my X and Y axis data below:

fchart = multiBarChart(name='f_multibarchart', width=1000, height=400, x_axis_format=None, color_category="category10")

xdata ['510', '125', '630', '625', '650', '1000', '805', '515', '610', '800']
ydata1 [0, 0, 0, 0, 1, 15, 0, 0, 0, 0]
ydata2 [1, 17, 23, 1, 29, 0, 0, 2, 0, 13]

fchart.add_serie(name="Full", y=ydata1, x=xdata)
fchart.add_serie(name="Low", y=ydata2, x=xdata)

Any help would be appreciated

Dusty Boshoff
  • 1,016
  • 14
  • 39

1 Answers1

2

Problem solved!

Setting reduceXTicks(false) did not work for me.

I found that the opacity of a missing X tick was set to 0, So what I did was to use the add_chart_extras() function to push the opacity to 1 for all ticks.

fchart = multiBarChart(name='f_multibarchart', width=1000, height=400, x_axis_format=None, color_category="category10")
extras = "d3.selectAll('#f_multibarchart text').style('opacity', '1');"
fchart.add_chart_extras(extras)

enter image description here

Dusty Boshoff
  • 1,016
  • 14
  • 39