Multicolor Scrolling Bar Graph

I am working on an Android application. In my application, I have to show a bar graph with several colors. Therefore, I used the Chart4j library. I used the code from the following chart4j example link.

Now the problem is that I can only show fixed bars, only if the number of bars exceeds the screen, which I could not scroll to view the remaining bars. Here is my screenshot. enter image description here 2

The following code I used to create the histogram.

public static String getBarChartUrl() { BarChartPlot team1 = Plots.newBarChartPlot( Data.newData( 25, 43, 12, 30,32,25, 43, 12, 30,32,25,25, 43, 12, 30,32,25 ), BLUEVIOLET, "Team A" ); BarChartPlot team2 = Plots.newBarChartPlot( Data.newData( 8, 35, 11, 5,9,25, 35, 11, 5,9,25,25, 43, 12, 30,32,25 ), ORANGERED, "Team B" ); BarChartPlot team3 = Plots.newBarChartPlot( Data.newData( 10, 20, 30, 30 ,15,32, 20, 30, 30 ,15,32,25, 43, 12, 30,32,25), LIMEGREEN, "Team C" ); // Instantiating chart. BarChart chart = GCharts.newBarChart( team1, team2, team3 ); // Defining axis info and styles AxisStyle axisStyle = AxisStyle.newAxisStyle( BLACK, 13, AxisTextAlignment.CENTER ); AxisLabels score = AxisLabelsFactory.newAxisLabels( "Score", 50.0 ); score.setAxisStyle( axisStyle ); AxisLabels year = AxisLabelsFactory.newAxisLabels( "Year", 50.0 ); year.setAxisStyle( axisStyle ); // Adding axis info to chart. chart.addXAxisLabels( AxisLabelsFactory.newAxisLabels( "2002", "2003", "2004", "2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017","2018" ) ); chart.addYAxisLabels( AxisLabelsFactory.newNumericRangeAxisLabels( 0, 100 ) ); chart.addYAxisLabels( score ); chart.addXAxisLabels( year ); chart.setSize( 600, 450 ); chart.setBarWidth( 50 ); chart.setSpaceWithinGroupsOfBars( 20 ); chart.setDataStacked( true ); chart.setTitle( "Team Scores", BLACK, 16 ); chart.setGrid( 100, 10, 3, 2 ); chart.setBackgroundFill( Fills.newSolidFill( ALICEBLUE ) ); LinearGradientFill fill = Fills.newLinearGradientFill( 0, LAVENDER, 100 ); fill.addColorAndOffset( WHITE, 0 ); chart.setAreaFill( fill ); String url = chart.toURLString(); return normalize( url ); } 

My problems

1) According to the data, the chart should display 17 bars, but it shows only 8 bars [year from 2002 to 2018, now its display until 2009]. How can I view the remaining columns by scrolling horizontally.

2) If the number of bars is less, then I can view the labels [represent each color for which data]. Please look at the image below bar chart with label

If the number is greater, I cannot view the label. Look at the first iamge.

3) I want to know if there is a way to give a separate background color for the border. I mean grades and years

Please help me find a solution

+4
source share
1 answer

If I'm not mistaken, charts4j uses WebView to display charts.

So add this line for WebView

 yourWebView.getSettings().setBuiltInZoomControls(true); 

This will enable scaling for WebView ,

Hope this helps ...

+1
source

Source: https://habr.com/ru/post/1487593/


All Articles