1

I am really struggling with Highcharts. We have an energy meter that exposes data via XML.

I've been tasked with making a dynamic spline chart similar to the demo, here: http://www.highcharts.com/demo/dynamic-update

Does anyone know if it's possible to use XML data (instead of a random number) to populate the y-axis?

The XML looks like this.

 <?xml version="1.0" encoding="UTF-8" ?>
<DAS>
<name>Main Campus</name>
<serial>05778</serial>
<devices>
<device>
<name>Building #1</name>
<records>
    <record>
    <point number="0" name="Electric" units="kWh" value="1564341.000"  /> 
    <point number="5" name="Water" units="gallons" value="764563.000"  /> 
    <point number="10" name="Gas" units="cu/ft hr" value="396380.000"  /> 
    <point number="15" name="Relative Humidity" units="%" value="67.175"  /> 
    <point number="20" name="Outdoor Air Temp" units="Deg. F" value="54.476"  /> 
    <point number="30" name="Indoor Temp" units="deg.F" value="71.324"  /> 
    </record>
</records>
</device>
</devices>
</DAS>

I've tried parsing the XML into JSON, but nothing seems to be working. Is it because the XML lacks a closing </point> tag? If I could get the kWh working I think I could get the rest of the points to work. Any examples or advice are much appreciated? Thanks much.

  • Does your actual xml have closing and tags? What have you actually tried? Do you have any code we could help you with? – Barbara Laird Aug 15 '16 at 22:03
  • You can use any data you want, but first you have to have it represented as a JavaScript object. See for example http://stackoverflow.com/q/9299642/215552 – Heretic Monkey Aug 15 '16 at 22:04
  • Yes, the XML does have closing `` and `` tags. I edited the original. Thanks! – Lewisandclark 200 Aug 15 '16 at 22:24
  • Here is a bit of code I've been trying to use. [http://pastebin.com/UrcxNwX2](http://pastebin.com/UrcxNwX2) – Lewisandclark 200 Aug 15 '16 at 22:41
  • ..and here are the [contents of array.php](http://pastebin.com/tKuYhCxr) Thank you! – Lewisandclark 200 Aug 15 '16 at 22:43
  • You'll need to parse the XML into JSON format so you can give it to HighCharts in the same way that the example uses for live data. Google for "convert XML to JSON" – Dr. Cool Aug 15 '16 at 23:22
  • Data from XML should be parsed and options object for a chart should be created or improved with the data from XML. More information in [this Docs](http://www.highcharts.com/docs/working-with-data/custom-preprocessing#2). Parsed data must match one of required by Highcharts [data formats](http:// api.highcharts.com/highcharts#series.data) Please describe how would you like to populate the y-axis - what kind of information do you need to set there, or just y values for data? A simple demo with your XML data, without a knowledge how should data be parsed: http://jsfiddle.net/m4nx4syp/ – Kacper Madej Aug 16 '16 at 10:27
  • Hello Kacper, thanks! The y-axis would be the value of each point. They do not necessarily need to be on the same chart either. – Lewisandclark 200 Aug 16 '16 at 14:35

0 Answers0