Good afternoon people.
I developed an app called test_chart that managed to run perfectly, I treated json the way I wanted it to appear on the chart.
I took this all the logic developed in test_chart to implement in another app that I am developing but the problem and in this other the graph does not appear.
I saw that some people already had this problem when using webpack that I am also using in the project that the graph is not working.
Is that the problem?
The app test_chart has no webpack configured and is working, but in the other that has webpack the chart does not appear being that in both app has the same implementation.
tns info
All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬──────────────────┐
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 3.3.0 │ 3.4.0 │ Update available │
│ tns-core-modules │ 3.3.0 │ 3.4.0 │ Update available │
│ tns-android │ 3.3.0 │ 3.4.0 │ Update available │
│ tns-ios │ 3.3.0 │ 3.4.0 │ Update available │
└──────────────────┴─────────────────┴────────────────┴──────────────────┘
Layout:
<
StackLayout
>
<
GridLayout
>
<!-- >> chart-angular-bar-series -->
<
RadCartesianChart
tkExampleTitle tkToggleNavButton>
<
CategoricalAxis
tkCartesianHorizontalAxis></
CategoricalAxis
>
<
LinearAxis
tkCartesianVerticalAxis></
LinearAxis
>
<
BarSeries
tkCartesianSeries [items]="chartResult"
categoryProperty
=
"hour"
valueProperty
=
"value"
showLabels
=
"true"
>
<
PointLabelStyle
tkBarLabelStyle
margin
=
"10"
fontStyle
=
"Bold"
fillColor
=
"#60B3FC"
textSize
=
"10"
textColor
=
"White"
></
PointLabelStyle
>
</
BarSeries
>
</
RadCartesianChart
>
<!-- << chart-angular-bar-series -->
</
GridLayout
>
</
StackLayout
>
File TS:
export class AppComponent implements OnInit {
chartResult: any[] = [];
ngOnInit() {
let data = [{
"start"
:
"2017-12-19T12:59:31.007Z"
,
"end"
:
"2017-12-19T13:05:58.304Z"
,
"value"
:
"346 count"
},{
"start"
:
"2017-12-19T12:50:57.321Z"
,
"end"
:
"2017-12-19T12:59:31.007Z"
,
"value"
:
"260 count"
},{
"start"
:
"2017-12-19T12:40:12.130Z"
,
"end"
:
"2017-12-19T12:41:07.690Z"
,
"value"
:
"55 count"
},{
"start"
:
"2017-12-19T12:30:12.283Z"
,
"end"
:
"2017-12-19T12:40:12.130Z"
,
"value"
:
"60 count"
},{
"start"
:
"2017-12-19T12:12:38.579Z"
,
"end"
:
"2017-12-19T12:15:47.882Z"
,
"value"
:
"27 count"
},{
"start"
:
"2017-12-19T12:03:16.669Z"
,
"end"
:
"2017-12-19T12:12:38.579Z"
,
"value"
:
"152 count"
},{
"start"
:
"2017-12-19T09:02:17.723Z"
,
"end"
:
"2017-12-19T09:04:11.171Z"
,
"value"
:
"42 count"
},{
"start"
:
"2017-12-19T08:53:00.599Z"
,
"end"
:
"2017-12-19T09:02:17.723Z"
,
"value"
:
"432 count"
},{
"start"
:
"2017-12-19T08:44:06.142Z"
,
"end"
:
"2017-12-19T08:53:00.599Z"
,
"value"
:
"211 count"
},{
"start"
:
"2017-12-19T08:31:34.791Z"
,
"end"
:
"2017-12-19T08:37:27.763Z"
,
"value"
:
"183 count"
},{
"start"
:
"2017-12-19T08:24:56.284Z"
,
"end"
:
"2017-12-19T08:31:34.791Z"
,
"value"
:
"23 count"
},{
"start"
:
"2017-12-19T08:16:45.160Z"
,
"end"
:
"2017-12-19T08:24:56.284Z"
,
"value"
:
"239 count"
},{
"start"
:
"2017-12-19T07:56:05.983Z"
,
"end"
:
"2017-12-19T08:02:30.153Z"
,
"value"
:
"743 count"
},{
"start"
:
"2017-12-19T07:46:08.378Z"
,
"end"
:
"2017-12-19T07:56:05.983Z"
,
"value"
:
"455 count"
}];
const getHour = date =>
new
Date(date).getUTCHours();
const onlyNumbers = el => el.replace(/[a-zA-Z+]/g,
''
);
const flatten = (acc, el) => {
const hour = getHour(el.start);
const value = Number(onlyNumbers(el.value));
const find = acc.find(f => f.hour === hour);
find
? (find.value += value)
: acc.push({
hour: hour,
value: value,
});
return
acc
};
this
.chartResult = _.orderBy(data.reduce(flatten, []), [
'hour'
], [
'asc'
]);
console.log(
'Chart : '
+ JSON.stringify(
this
.chartResult));
}
}
============
json result:
[ { hour: 12, value: 900 },
{ hour: 9, value: 42 },
{ hour: 8, value: 1088 },
{ hour: 7, value: 1198 } ]
I did import correctly in app.module.ts:
import {NativeScriptUIChartModule} from "nativescript-pro-ui/chart/angular";
imports: [NativeScriptModule, NativeScriptUIChartModule]