I have created pie chart using chartist.js I am not able to create responsive web design. When I reduce window size i.e for small window the legend should go above pie chart and for large window size the legend should be on right hand side. So for large size it works but for small screen size the legend is overlapping piechart. How can I style legend so that for small screen it will go above pie chart and not overlap piechart.
Note: I have created piechart as a react component.
Chartist legend docs: https://github.com/CodeYellowBV/chartist-plugin-legend/blob/master/index.html
Code:
React component i.e pie chart:
import React, { Component } from 'react';
var options = {
width:200,
height:200,
showLabel:false,
stackBars:true,
plugins: [
Chartist.plugins.legend()
]
};
class Pie extends Component {
constructor(props){
super(props);
}
const data = {
labels: labels,
series: dismissals
};
this.piechart = new Chartist.Pie('.ct-pie-chart', data, options);
}
render(){
return(
<div className="row">
<div className="col-12 col-sm-6 col-lg-8">
<div className="ct-pie-chart">
{this.piechart}
</div>
</div>
</div>
)}
}
export default Pie ;
CSS file:
.ct-pie-chart .ct-legend li.inactive:before {
background: transparent;
}
.piechart-title {
text-align: center;
}
.ct-pie-chart .ct-legend {
position: absolute;
padding-left: 80px;
}
.ct-pie-chart .ct-legend.ct-legend-inside li{
display: block;
margin: 0;
}
Screenshot (For small and large screen) :
I Added following css but it does not work:
.ct-pie-chart {
display: flex;
align-items: flex-start;
}
.ct-pie-chart .ct-legend {
position: absolute;
padding-left: 80px;
}