I'm doing a combo scatter and line charts (it's a electoral poll tracker) following this example from HC docs:
series: [{
type: 'scatter',
name: 'Party1',
data: [10.1,9.2,9.8]
}, {
type: 'scatter',
name: 'Party2',
data: [6.5,6.5,6.8]
}, {
type: 'spline',
name: 'Party1-tracker',
data: [10.1,9.8,10.0]
}, {
type: 'spline',
name: 'Party2-tracker',
data: [6.5,6.5,6.6]
}]
On another document, I can make a chart from a Google Spreadsheet. I've followed this Jack Dougherty example: https://jackdougherty.github.io/highcharts-with-google-sheets/bubble.html
data: {
// insert the key from your public Google Sheet
googleSpreadsheetKey: '1fYJOd-2agLPg38qhblS8qoZGWGkKcK-3uTsMpf37Hys',
// insert Google Sheet column headers (x, y, z...) to match column numbers (0, 1, 2...)
seriesMapping: [{x: 0, y: 1, z: 2, name: 3, country: 4, category: 5}],
complete: function(data) {
categoriesIntoSeries(data);
changeSeriesColors(data);
}
},
plus
/**
* Here, all data is split into categories depending on the 'category' property
* Needed for correct legend display
*/
function categoriesIntoSeries(data) {
rows = data.series[0].data;
data.series = [];
for (i = 0; i < rows.length; i++) {
cat = rows[i].category;
catExists = false;
for (j = 0; j < data.series.length; j++) {
if (data.series[j].name == cat) {
// Add a data point to existing series
data.series[j].data.push(rows[i]);
catExists = true;
}
}
if (!catExists) {
// When category is encountered for the first time, create a series
data.series.push({name: cat, data: [rows[i]]})
}
}
}
What I've tried unsuccessfully is (maybe it's impossible) to connect each column from my spreadsheet to each 'series' element. Something like this:
{
type: 'scatter',
name: 'Party1',
data: /*get data from spreadsheet column 1 or a json field*/
}
I'll be thankful if you can tell us if it's possible and, if yes, point me to some documentation or example on how to do this
You can use seriesMapping array for this. It should contain a mapping for every column from the sheet.
Refer to this live demo: http://jsfiddle.net/kkulig/b45s1Luh/
seriesMapping: [{
x: 0,
y: 1 // first column series
}, {
x: 0,
y: 2 // second column series
}, {
x: 0,
y: 3 // third column series
}]
}
API reference: https://api.highcharts.com/highcharts/data.seriesMapping
Related
Full example:
https://jsfiddle.net/gbeatty/4byg0p2t/
data: {
table: 'datatable',
startRow: 0,
endRow: 6,
startColumn: 0,
endColumn: 3,
parsed: function (columns) {
columns.forEach(column => {
column.splice(1, 2);
});
}
},
What I'd like the chart to reference is only column 0 "Year" and column 3 "Group C" while keeping the entire table displayed below. Challenge is disregarding the 2 columns in the middle.
I am trying the parsed option but it seems the rows and columns are mixed up. I even tried setting the switchRowsAndColumns value to true. (https://api.highcharts.com/highcharts/data.seriesMapping)
You can also use complete function to modify your data.
Example code based on your config:
complete: function(options) {
let series = [];
series.push(options.series[2]);
options.series = series;
}
Demo:
https://jsfiddle.net/BlackLabel/tfs4ubcL/
API Reference:
https://api.highcharts.com/highcharts/data.complete
Elaborating a graph where I point with y different, and 'x' equals; I put in the series:
series: [{
name: 'Grafico 1',
data: data,
dataLabels: {
enabled: true,
formatter: function () {
return Highcharts.numberFormat(this.y, 2)
},
color: "#000000"
},
stacking: 'normal',
}]
and as a result in the chart have the highest value added with the smaller one, that is:
http://i.imgur.com/Ups7AzT.png
If I remove the statement "stacking: 'normal'", I instead the chart without the line joining the points:
http://i.imgur.com/gMAO5VW.png
I ask: you can have the chart without the value added is greater than the lower (ie the value 18 is represented as 18 in the chart, and 26.45 because the child is 8.45)?
I'm trying to specify column charts with objects for points. The reason for this is that I don't have to then split up the array of objects into separate arrays of categories and values.
I have tried the following, but neither works. (I'm interested in both specifying the category for columns, and specifying datetimes for x values.)
var data_1 = [
{x:new Date('2013-01-03'),y:2},
{x:new Date("2013-01-02"),y:6},
{x:new Date("2013-01-01"),y:4},
];
var data_2 = [
{category: "a", y: 3},
{category: "b", y: 3},
{category: "c", y: 4}
];
var create_chart = function(el, data){
var init_obj = {
chart: {
type: 'column'
},
series: [{
name: 'a',
data: data
}]
};
el.highcharts(init_obj);
};
create_chart($('#chart1'), data_1);
create_chart($('#chart2'), data_2);
In highcharts configuration you can set onyl one type of one xAxis. If xAxis has datetime type, you cannot use categoires. Only wayt o common both types is use two xAxis with different types.
series: [{
type: 'flags',
name: 'Flags on axis',
data: [{
x: Date.UTC(2011, 2, 1),
title: 'A'
}, {
x: Date.UTC(2011, 5, 1),
title: 'C'
}],
shape: 'squarepin'
}]
$("#btnAddFlag").click(function () {
chart.series[0].setData(
{
x: Date.UTC(2011, 2, 1),
title: 'B'
});
});
Above code is part of highstock chart option and I want to add flag based on user event click. However I able to add the new point flag into the chart but the existing flags which title A and C will be missed out.
how can I add the new flag into the chart with the existing flags ?
On the other hand, I am able get the flag data but I'm unsure to
generate the correct data structure and reinitialize the old and new
flag data back into the chart.
Thank you.
Use addPoint instead of setData.
http://api.highcharts.com/highstock#Series.addPoint()
$("#btnAddFlag").click(function () {
chart.series[0].addPoint({
x: Date.UTC(2011, 2, 1),
title: 'B'
});
});
How do I display the date on my x axis from a json object structured like so;
[
[
634420512000000000,
100000
],
[
634421376000000000,
100086
],
[
634422240000000000,
100171
],
[
634423104000000000,
100257
]
]
Where my date is in milliseconds. I have set my xAxis like so;
xAxis: {
title: {
text: 'Time'
},
type: 'datetime'
}
Highcharts accepts three primary formats for data:
A simple array (e.g. [1, 2, 3])
An array of arrays of x, y pairs (e.g. [[x, y], [x2, y2]])
A list of point objects
Further details on these formats can be found in the highcharts documentation. However, in your case, it should be quite easy. Just do something like the following.
var data = []; //assume data is the array you've listed in your question
var chart = new Highcharts.chart({
xAxis: {
title: {
text: 'Time'
},
type: 'datetime'
},
series: [{
data: data
}]
});
Turns out I was returning ticks instead of milliseconds from 1/1/1970
So...
Dim dt1970 As DateTime = New DateTime("1970", "1", "1")
Dim d As DateTime = row("myDateFromDB")
Dim span As TimeSpan = d - dt1970
Dim milli as long = span.TotalMilliseconds