Using amchart4, I have problems to draw a XYChat with Y-axis as a category-axis (string values), and having multiple series for that.
When I only have one seri which I can set yAxis.dataFields.category there is no problem. Also if I have two series with y-axis as a value-axis (numerical value) there is no problem. The problem happened with Y-category-axis and multiple series.
Here is my code:
let myData = [
{
title: "2",
//y:6,
//y1:9,
customer1: "Internet_BB",
customer2: "Space",
},
{
title: "1",
//y:12,
//y1:6,
customer1: "Cloud_transmission_BB",
customer2: "Internet_BB",
},
{
title: "rhs",
//y:5,
//y1:7,
customer1: "COLOCATION",
customer2: "InternalData_BB_(NIN)",
}
];
am4core.useTheme(am4themes_animated);
var chart = am4core.create("XYChartDiv", am4charts.XYChart);
chart.data = myData;
var xAxis = chart.xAxes.push(new am4charts.CategoryAxis());
xAxis.dataFields.category = "title";
var yAxis = chart.yAxes.push(new am4charts.CategoryAxis());
// var yAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
var series1 = chart.series.push(new am4charts.LineSeries());
series1.dataFields.categoryY = "customer1";
// series1.dataFields.valueY = "y"
series1.dataFields.categoryX = "title";
series1.name = "customer1";
series1.strokeWidth = 3;
series1.tooltipText = "{name} in {categoryX}: {categoryY}";
series1.legendSettings.valueText = "{categoryY}";
var series2 = chart.series.push(new am4charts.LineSeries());
series2.dataFields.categoryY = "customer2";
// series2.dataFields.valueY = "y1"
series2.dataFields.categoryX = "title";
series2.name = "customer2";
series2.strokeWidth = 3;
series2.tooltipText = "{name} in {categoryX}: {categoryY}";
series2.legendSettings.valueText = "{categoryY}";
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomY";
chart.legend = new am4charts.Legend();