Android
Library that provides a set of Charts components required to build new products.
Getting Started
- Example
- Installing
- Readme
- Changelog
For creating LineChart you should create data provider which extended BaseLineChartDataProvider
and pass it to ChartContainerView
.
Example of creating data provider for LineChart:
class LineChartDataProvider(/*..*/) : BaseLineChartDataProvider(/*..*/) {
// function for providing list of RawRecord values
override fun getRawRecords(result: (unit: String, List<RawRecord>) -> Unit) {
// get raw records values here
result("subtitle", listOf(RawRecord(/*..*/)))
}
// function for providing input data to chart
override fun getData(
chartRange: ChartRangeType, // type of time range on chart
accuracyCoefficient: Long, // timeline accuracy factor on chart
chartSubcategoryId: ChartSubcategoryId, // ID value of chart subcategory
result: (InitialChartData) -> Unit // lambda should be invoked to provide result of input data
) {
// set data for chart here and convert it to List<LineChartData> type
result(InitialChartData.LineChart(listOf(LineChartData(/*..*/))))
}
}
For BarChart you should create the same data provider extended from BaseBarChartDataProvider
.
Creating view of LineChart or BarChart will be depend on type of data provider that you pass to ChartContainerView
.
Adding ChartContainerView
component in the layout:
<com.huma.sdk.charts.chart_container.ChartContainerView
android:id="@+id/chartContainer"
android:layout_width="0dp"
android:layout_height="65dp"
app:layout_constraintWidth_percent="0.5" />
Creating instance of ChartContainerView
component from code:
return ChartContainerView(context).apply {
this.chartDataProvider = dataProvider // instance of your ChartDataProvider implementation class
this.config = chartConfig // instance of ChartConfig class with configuration chart view
this.configs = chartUnitConfig // instance of ChartUnitConfig class with configuration of chart subcategory item
}
- Add the dependency in your local build.gradle file:
implementation("com.huma.sdk:charts:<latest-version>")
- Initialize
HumaChartsManager
in your Application class:
HumaChartsManager.init()
Huma Chart module is dedicated to creating LineChart and BarChart using MPAndroidChart library.
ChartContainerView - add this view to your layout for using charts.
ChartDataProvider - is a base interface contains definitions of main methods to providing data to chart views.
BaseChartDataProvider - abstract class extends ChartDataProvider
and defines methods which describes steps of calculation and preparing data before display on chart and handling events in process of interacting with charts.
For example that include sorting, filtering data by ranges, calculating average values and data for single selected point etc.
BaseLineChartDataProvider - extends BaseChartDataProvider
and defines logic of preparing data specific for LineChart.
BaseBarChartDataProvider - extends BaseChartDataProvider
and defines logic of preparing data specific for BarChart.
LineChartDataProcessor - contains impelmentation of processing row input data to data type which used to dispaly items on LineChart.
BarChartDataProcessor - contains impelmentation of processing row input data to data type which used to dispaly items on BarChart.
LineChartData - use this class to set row input data for LineChart.
BarChartData - use this class to set row input data for BarChart.