I am trying to plot stock prices using GraphView library over multiple days with Days on the X-axis. I am able to figure out how to use dates on X-axis by overriding formatlabel. But I run into an issue where the graph shows discontinuities when there is no Y-axis value. For eg: I am getting stock price data every 5min for 5 days and want the X-axis labels to appear for each day (in "dd" format) and the plot should only include data for the market working hours. But the plot seems to include even data after market-close resulting in discontinuities like the plot below. Also, I want to show X-axis labels only for each start of the day and not any random values that are picked by GraphView (expected plot is included). Another issue I observed is that even if set number of horizontal labels using graph.getGridLabelRenderer().setNumHorizontalLabels(5) it does not work. I still see only 2 labels. I even tried setting HumanRounding to false. This makes it even worse as it displays all the values and the X-axis labels are overlapping and not visible

SimpleDateFormat sdf_1w = new SimpleDateFormat("dd");

//Here is the override for formatLabel() to display X-axis in Date format

graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter()
                {
                    @Override
                    public String formatLabel (double value, boolean isValueX) {
                        if (isValueX) {
                            return sdf_1w.format(new Date((long) value));
                        } else {
                            return super.formatLabel(value, isValueX);
                        }
                    }
                });
                graph.getGridLabelRenderer().setNumHorizontalLabels(5);
graph.getGridLabelRenderer().setNumVerticalLabels(5);
graph.getGridLabelRenderer().setHumanRounding(false);

Here is the plot I get (with HumanRounding=false):

This is the expected Plot: enter image description here

0 Answers