Kalu Khan Luhar
Kalu Khan Luhar

Reputation: 1074

Set String values on x-axis on graph?

I have a lineGraph with float values on both x-axis and y-axis? My question is that how can i set String values on x-axis like date or name of months.I am using GraphView-3.0.jar library.my code is

values_list.add(1.0);
values_list.add(5.0);
values_list.add(9.0);
values_list.add(12.0);
values_list.add(17.0);
values_list.add(1.0);
values_list.add(13.0);
values_list.add(23.0);
graphData = new GraphViewData[(values_list.size())];
double price_copy = 0;
for (int i = 0; i < values_list.size(); i++) {
    price_copy = values_list.get(i);
    graphData[i] = new GraphViewData(i, price_copy);

}
GraphView graphView;

graphView = new LineGraphView(this // context
        , "" );// graphView.addSeries(exampleSeries);// data
graphView.addSeries(new GraphViewSeries("values",
        new GraphViewStyle(Color.rgb(00, 00, 128), 3),
        graphData));

graphView.setShowLegend(true);
// set view port, start=2, size=40
graphView.setViewPort(0, 10);
graphView.setScalable(true);
graphView.setScrollable(true);

LinearLayout layout = (LinearLayout) findViewById(R.id.LNL_CHART);
layout.addView(graphView);

Also i have no idea about AchartEngine,thanks in advance.

Upvotes: 3

Views: 2876

Answers (2)

appsthatmatter
appsthatmatter

Reputation: 6417

Just use the label formatter. You could store your x-labels as string in an array.

For example:

final String[] xLabels = new String[] {
  "foo", "bar", "third", "bla", "more"
};
GraphView graphView = new LineGraphView(this, "example") {
   @Override
   protected String formatLabel(double value, boolean isValueX) {
      if (isValueX) {
         return xLabels[(int) value];
      } else {
         // return y label as number
         return super.formatLabel(value, isValueX); // let the y-value be normal-formatted
      }
   }
};

Upvotes: 0

sumit acharya
sumit acharya

Reputation: 629

Use achart engine library. you can search for that on google. it helped me.Thanks

Upvotes: 1

Related Questions