多色条形图与滚动

4
我正在开发一款Android应用程序。在我的应用中,我需要显示一个带有多种颜色的条形图,因此我使用了charts4j库。我使用了以下链接中的代码 charts4j示例
现在的问题是,如果条形数量超过屏幕范围,我只能显示固定数量的条形,无法滚动查看其余的条形。以下是我的截图。 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年]。如何通过横向滚动查看其余的柱形图。

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

如果数量较多,则无法查看标签。请参见第一张图片。

3) 我想知道是否有办法为边框单独设置背景颜色。 我的意思是分别为成绩和年份设置。

请帮我找到解决方案。


1
您指定的链接无效。 - amalBit
@amalBit...抱歉,请现在检查链接。 - sarath
你可以将主要布局更改为水平滚动视图。 - amalBit
指出问题加一分... - CRUSADER
1个回答

1
如果我没记错的话,charts4j 使用 WebView 来显示图表。
因此,请在您的 WebView 中添加此行。
yourWebView.getSettings().setBuiltInZoomControls(true);

这将为WebView提供缩放功能,
希望这可以帮到你...

@CRUSADER.. 已经有了缩放功能..但我无法查看所有的条形图..我需要一个水平滚动条来查看整个条形图。 - sarath
你能否发布从charts4j获取的URL,以便在Webview中显示? - CRUSADER
1
@sarath,我从上面提供的链接中明白了你的意思。是的,图表返回了部分数据,因为请求的数据太大了。这确实是charts4j的缺陷之一。你可以通过这个链接直接向谷歌报告这个问题。 - CRUSADER
有很多选择,你需要检查哪个最适合你。试试这个:http://androidplot.com/ 或者这个:http://www.achartengine.org/content/goodies.html 甚至是这个:http://rakhi577.wordpress.com/2012/10/11/bar-chart-in-android-with-out-any-built-in-jars/ - CRUSADER
是的,你说得对。这就是为什么我建议尽可能多地浏览符合你特定要求的选项,即更多的条形数据... 如果你喜欢afreechart.. 就选择它吧... - CRUSADER
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接