多色条形图与滚动

时间:2013-06-22 06:36:16

标签: android bar-chart charts4j

我正在开发Android应用程序。在我的应用程序中,我必须显示多种颜色的条形图所以我使用了chart4j库。我使用了以下链接charts4j example中的代码。

现在问题是我只能显示固定条只有当条数超过屏幕我无法滚动查看剩余的条。这是我的截图。 enter image description here 2

以下是我用来生成条形图的代码。

 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 );
}

我的问题是

1)根据数据,图表必须显示17个柱,但它仅显示8个柱[从2002年到2018年,现在仅显示到2009年]。如何通过水平滚动查看剩余的柱。 / p>

2)如果条形数量较少,那么我可以查看标签[代表数据的每种颜色]。请查看下图bar chart with label

如果数量更多,那么我无法查看标签。请参阅第一个iamge。

3)我想知道有没有办法为边框提供单独的背景颜色。我的意思是分数和年份

请帮我找一个解决方案

1 个答案:

答案 0 :(得分:1)

如果我没有弄错,charts4j使用WebView来显示图表。

因此,请为WebView

添加此行
yourWebView.getSettings().setBuiltInZoomControls(true);

这将为WebView

提供缩放功能

希望这会有所帮助......

相关问题