code refactoring in chart.builder