Charts are used to display set of data in an analytical manner such that an observer can easily come to a conclusion by just looking at it without having to go through all the numerical data sets. Legends are used to differentiate a set of data set from another set. Generally, different colors and different names are used to form a legend in a chart.
MPAndroidChart is an amazing library with the capability of generating different types of graphs in an Android device. In PSLab several user interfaces are implemented using LineCharts to display different waveforms such as readings from channels attached to PSLab device, logic levels etc.
When several data sets are being plotted on the same graph area, legends are used. In PSLab Android application, Oscilloscope supports four different type of waveforms to be plotted on the same graph. Logic Analyzer implements one to four different types of logic level waveforms on the same plot. To identify which is which, legends with different colors can be used rather than just the names. For the legends to have different colors, it should be explicitly set which color should be held by which data set. Otherwise it will use the default color to all the legends making it hard to differentiate data lines when there are more than one data set is plotted.
Assume a data set is generated from a reading taken from a probe attached to PSLab device. The set will be added as an Entry to an array list as follows;
ArrayList<Entry> dataSet = new ArrayList<Entry>();
The next step will be to create a Line Data Set
LineDataSet lineData = new LineDataSet(dataSet, "DataSet 1");
This LineDataSet will contain sample values of the waveform captured by the microprocessor. A LineDataSet object support many methods to alter its look and feel. In order to set a color for the legend, setColor() method will be useful. This method accepts an integer as the color. This method can be accessed as follows;
MPAndroidChart provides different sets of colors under ColorTemplate. This class has several predefined colors with five colors in each color palette are added by the developers of the library and they can be accessed using the following line of code by simply calling the index value of the palette array list.
Set of color palettes available in the ColorTemplate class are;
The following demonstrates how the above activities produce a line chart with three different data sets with different colored legends.
This implementation can be used to enhance the readability of the waveforms letting user being able to differentiate between one waveform from another in PSLab Android application.
- MPAndroidChart Repository: https://github.com/PhilJay/MPAndroidChart
- Line Charts: https://en.wikipedia.org/wiki/Line_chart
- MPAndroidChart Line Chart Tutorial: https://www.numetriclabz.com/android-line-chart-using-mpandroidchart-tutorial/
- MPAndroidChart Legends tutorial: https://www.studytutorial.in/android-line-chart-or-line-graph-using-mpandroid-library-tutorial
PSLab official web site: https://pslab.fossasia.org/
You must log in to post a comment.