【问题标题】:Multicolor bar chart with scroll带滚动条的多色条形图
【发布时间】:2013-06-22 06:36:15
【问题描述】:

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

现在的问题是,只有当条数超过屏幕时,我才能仅显示固定条,我无法滚动查看剩余条。这是我的屏幕截图。 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)如果条数较少,我可以查看标签[代表每种颜色的数据]。请看下图

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

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

请帮我找到解决办法

【问题讨论】:

  • 您指定的链接无效
  • @amalBit...sorry.now 检查链接
  • 您可以将主布局更改为水平滚动视图
  • +1 指出问题...

标签: android bar-chart charts4j


【解决方案1】:

如果我没记错的话charts4j 使用WebView 来显示图表。

所以,为您的WebView 添加这一行

yourWebView.getSettings().setBuiltInZoomControls(true);

这将为WebView 提供缩放功能,

希望这会有所帮助...

【讨论】:

  • @CRUSADER.. 缩放了..但我无法查看所有条形图..我需要水平滚动才能查看整个条形图。
  • 你能把你从charts4j得到的用于在Webview中显示的url贴出来
  • @CRUSADER...查看我上面评论的网址
  • @sarath,现在我从上面提供的链接中得到了你的观点。是的,图表确实返回了部分数据,因为请求的数据太大。这确实是charts4j的缺陷之一。你可以通过link.. 直接向谷歌报告这个问题。
猜你喜欢
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-04
相关资源
最近更新 更多