Hi, I am developing android app in android studio in JAVA. And I am using DataChartView to display a chart the problem is I am unable to see anything plotted. There is just one grey line. Following is my code using the sample data from the documentation
public class CategoryDataSample extends CategoryDataCollection { public CategoryDataSample() { this.add(new CategoryDataPoint("A", 85, 80, 95)); ... this.add(new CategoryDataPoint("B", 50, 45, 65)); this.add(new CategoryDataPoint("Z", 100, 75, 95)); int i = 0; for (CategoryDataPoint dataPoint : this) { dataPoint.setIndex(i++); } }
public class CategoryDataPoint { private int _index; private String _category; private double _value; private double _high; private double _low; public CategoryDataPoint(String category, double value, double high, double low) { _category = category; _value = value; _high = high; _low = low; } public CategoryDataPoint(String category, double value) { _category = category; _value = value; } public int getIndex() { return _index; } public int setIndex(int value) { _index = value; return _index; } public String getCategory() { return _category; } public String setCategory(String category) { _category = category; return category; } public double getValue() { return _value; } public double setValue(double value) { _value = value; return _value; } public double getHigh() { return _high; } public double setHigh(double value) { _high = value; return _high; } public double getLow() { return _low; } public double setLow(double value) { _low = value; return _low; }}
and the 3rd class is following
class CategoryDataCollection extends ArrayList<CategoryDataPoint> {}
And below is my usage in Fragment
CategoryDataSample data = new CategoryDataSample();DataChartView chart = new DataChartView(chartContainer.getContext());chart.setHorizontalZoomable(true);chart.setVerticalZoomable(false);NumericYAxis yAxis = new NumericYAxis();yAxis.setLabel("y");yAxis.setLabelTextSize(10.0f);CategoryXAxis xAxis = new CategoryXAxis();xAxis.setDataSource(data);xAxis.setLabel("x");xAxis.setLabelTextSize(10.0f);chart.addAxis(xAxis);chart.addAxis(yAxis);LineSeries series = new LineSeries();series.setDataSource(data);series.setValueMemberPath("");series.setTitle("Coal");series.setXAxis(xAxis);series.setYAxis(yAxis);chart.addSeries(series);chartContainer.addView(chart);
chartContainer is a FrameLayout in my XML
the only output I get is a grey line which is so wierd as i am following the exact same code provided in the documentation. Please help.
Hello Hasham,
Thank you for your post.
The code samples that you have provided all look ok, with the exception of a couple parts in the Fragment (last screenshot). Looking at the sample code that you have provided, I see three issues that may lead to you not seeing anything in the DataChartView.
The first two issues are the parameters for the "setLabel" method of your DataChartView's axes. You currently have them set to x and y for the X and Y axis, but there does not exist an X or a Y property on your data item. This also does not really need to be set on the NumericYAxis, as that axis will format its own labels based on the series that exist in the DataChartView by default, and so I would recommend that you remove the setLabel setter for the NumericYAxis in this case. Looking at your data source, it looks like the "Category" property is the one that you are looking to use for the categories in your chart, and so I would recommend setting the XAxis Label to "Category" in this case.
The final issue exists in your LineSeries, as the setValueMemberPath is currently taking an empty string as a parameter. You will need to point this at one of your numeric properties in your underlying CategoryDataPoint class. I would imagine that if you make the necessary changes to your axes as mentioned above, and then set the ValueMemberPath to either "High", "Low", or "Value," that you should see a plot of data in your DataChartView.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Thanks for you help. I am noe actually able to see the chart. There is one more thing can you tell me what is the Android equivalent to hostView.theme = [IGChartGradientThemes FinanceTheme3]; ?
How can I apply FinanceTheme3 on Android? As it is available in iOS?
The Android-specific product that you are using in order to use the DataChartView control was developed completely separate to our NucliOS product, and as such, the FinanceTheme3 theme, and all of the themes that exist on NucliOS do not exist in the Android product. You may be able to mimic this theme by using the many brush-related methods of the XamDataChart and its series and defining a LinearGradientBrush for your series brushes.
If you would like to see the NucliOS themes ported over to Android, I would recommend suggesting a new product idea for this at http://ideas.infragistics.com. This product ideas site will place you in direct communication with our product development teams who plan and prioritize upcoming features and products based on community and user feedback.
Please let me know if you have any other questions or concerns on this matter.