简体   繁体   中英

How to create a chart in CanvasJS with an undetermined number of Y Axis?

I am updating my charts dynamically from an external JSON object.

My chart will display multiple Y axis and the number of Y axis is determined by the volume of data read in from the JSON file.

How do I create a chart with an undetermined number of Y Axis? It seems you need to explicitly state the number of Y axis in the

data: [
]

section like

    data: [
    {
    name: "YAxis1",
    type: "splineArea",
    yValueFormatString: "#,### First Data",
    showInLegend: true,
    legendText: "First Data",
    dataPoints : dataPointsFirst
  },
  {
    name: "Second Data",
    type: "splineArea",
    yValueFormatString: "#,### Second Data",
    showInLegend: true,
    legendText: "Second Data",
    dataPoints : dataPointsSecond
  }]

Is there a way to dynamically adapt the chart to add a line in the chart to the Y axis?

EDIT: The JSON object takes this form:

[
    {
        "id" : "4568ID214",
        "data" : [12, 65, 45, 32, 67]
    },
    {
        "id" : "5687ID556",
        "data" : [76, 64, 55, 41, 90]
    }
]

Where each 'data' element will have its own line correlating to the Y axis. However, the number of id & data objects is undetermined. It could be 5 or 50.

You can use the JSON object to push data into the 'data' variable.

I assume that your object contains objects, so each secondary object must have the data required for an element in the 'data' array.

{
    'obj0': {'data0': 'abcd', 'data1': 'efgh'},
    'obj1': {'data0': 'ijkl', 'data1': 'mnop'}
}

For that example input, you can use 'obj0' and 'obj1' to create an object with your chart data. Of course, that's just an example. You will need to either calculate the data points or edit the question with the JSON response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM