How to import a datatable (.txt) to Amchart with two different delimiters between the columns?

How to import a datatable (.txt) to Amchart with two different delimiters between the columns?

mtazrartmtazrart Posts: 3Questions: 1Answers: 0
edited September 2019 in Free community support

I want to import the data from myfile.txt (see attachment) file under amchart in order to make figures later.

Nevertheless, the columns of my table are separated by two delimiters. The delimiter between the first and the second column is the comma, then for the rest of the columns it is the space.

I used in the code below the command "delimiter" twice (once to define the commas and another time to define the spaces) but without giving results.

Can you please correct my code below !

Thank you in advance

Here is my code :

// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);

// Set up data source

chart.dataSource.url = "https://..../amchart/myfile.txt";
chart.dataSource.parser = new am4core.CSVParser();

chart.dataSource.parser.option.delimiter = ",";
chart.dataSource.parser.option.delimiter = "\t";

chart.dataSource.parser.options.useColumnNames = false;

// Create axes

var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "col1";

// Create value axis
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

// Create series
var series1 = chart.series.push(new am4charts.LineSeries());
series1.dataFields.valueY = "col2";
series1.dataFields.categoryX = "col1";
series1.name = "P";
series1.strokeWidth = 1;
series1.tensionX = 0.7;
series1.bullets.push(new am4charts.CircleBullet());

var series2 = chart.series.push(new am4charts.LineSeries());
series2.dataFields.valueY = "col3";
series2.dataFields.categoryX = "col1";
series2.name = "T";
series2.strokeWidth = 1;
series2.tensionX = 0.7;
series2.bullets.push(new am4charts.CircleBullet());

var series3 = chart.series.push(new am4charts.LineSeries());
series3.dataFields.valueY = "col4";
series3.dataFields.categoryX = "col1";
series3.name = "V";
series3.strokeWidth = 1;
series3.tensionX = 0.7;
series3.bullets.push(new am4charts.CircleBullet());

// Add legend
chart.legend = new am4charts.Legend();

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    How does this relate to DataTables?

  • mtazrartmtazrart Posts: 3Questions: 1Answers: 0

    The question is how to analyze an external data table !

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I don't think you are using DataTables. If you are referring to your text file as "an external data table", that has nothing to do with this forum.
    If you are using DataTables, then please show some relevant code.

  • mtazrartmtazrart Posts: 3Questions: 1Answers: 0
    edited September 2019

    But I gave my code below my question!
    If you do not have an answer to my question! why give comments that help nobody! Let others give me a track please!

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I asked for relevant code - code which shows some use of the DataTables plug-in for jQuery.

This discussion has been closed.