I am trying to update the data series on the update button by providing new series. As the result, new series will be a plotting along with the old series.
And After plotting the new series, the values on are X-axis is clear up. Here I Am attaching the code snippet please have look.
Initial State config:
this.state = {
chartOptions: {
credits: {
enabled: false,
},
chart: {
type: 'spline',
},
title: {
text: 'Chart',
},
plotOptions: {
series: {
shadow: false,
marker: {
enabled: false,
},
},
},
xAxis: {
gridLineWidth: 1,
type: 'datetime',
lineColor: '#999',
lineWidth: 1,
title: {
text: 'Time',
style: {
color: '#000',
},
},
},
yAxis: [
{
title: {
text: 'Value',
},
gridLineWidth: 1,
lineWidth: 1,
opposite: true,
plotLines: [
{
color: '#55c2ea',
width: 2,
value: props.data[0][1], // Need to set this probably as a var.
label: {
text: props.data[0][1],
textAlign: 'left',
verticalAlign: 'middle',
style: {
color: '#55c2ea',
fontSize: 16,
borderWidth: 1,
backgroundColor: '#55c2ea',
borderColor: '#55c2ea',
},
x: 330,
},
},
],
accessibility: {
enabled: true,
},
opposite: true,
},
],
time: {
useUTC: false
},
series: [
{
showInLegend: false,
color: '#FF0000',
data: props.data.slice(0, props.tradingInterval),
},
],
}
};
Update Function:
updateSeries = () => {
this.setState({ chartOptions: {
series: [
{
showInLegend: false,
color: '#FF0000',
data: this.props.data.slice(0, 15),}
]
} })
}
Graph Render code:
render() {
return (
<View style={styles.container}>
<HighchartsReactNative
styles={styles.chart}
options={this.state.chartOptions}
/>
<Button
title="Refresh"
onPress={this.updateSeries.bind(this)}/>
</View>
);
}
After updating graph looks like
Class Component Code: https://gist.github.com/cupatil/da00b0ab0866e3a4f9306f0425e92582
Also tried this code using a functional component.
Using Functional Component Code: https://gist.github.com/cupatil/2fc1862f64f3a511158ced3c6b64d215
But the same thing happens series changed but not able to plot the graph property as per the image. Also, X-Axis data not calculated properly.
Sample Series data that I am using:
[ { x: 1607883000000, y: 1.6093 },{ x: 1607882940000, y: 1.6094 },{ x: 1607882880000, y: 1.6093 },{ x: 1607882820000, y: 1.6094 },{ x: 1607882760000, y: 1.6094 },{ x: 1607882700000, y: 1.6094 },{ x: 1607882640000, y: 1.6095 },{ x: 1607882580000, y: 1.6094 },{ x: 1607882520000, y: 1.6095 },{ x: 1607882460000, y: 1.6093 },{ x: 1607882400000, y: 1.6095 },{ x: 1607882340000, y: 1.6095 },{ x: 1607882280000, y: 1.6088 },{ x: 1607882220000, y: 1.6096 },{ x: 1607882160000, y: 1.6095 },{ x: 1607882100000, y: 1.6096 },{ x: 1607882040000, y: 1.6096 },{ x: 1607881980000, y: 1.6096 },{ x: 1607881920000, y: 1.6097 },{ x: 1607881860000, y: 1.6097 },{ x: 1607881800000, y: 1.6099 },{ x: 1607881740000, y: 1.6101 },{ x: 1607881680000, y: 1.61 },{ x: 1607881620000, y: 1.61 },{ x: 1607881560000, y: 1.6099 },{ x: 1607881500000, y: 1.6099 },{ x: 1607881440000, y: 1.6099 },{ x: 1607881380000, y: 1.6098 },{ x: 1607881320000, y: 1.6099 },{ x: 1607881260000, y: 1.6098 },{ x: 1607881200000, y: 1.6098 },{ x: 1607881140000, y: 1.6098 },{ x: 1607881080000, y: 1.6099 },{ x: 1607881020000, y: 1.6098 },{ x: 1607880960000, y: 1.6099 },{ x: 1607880900000, y: 1.6098 },{ x: 1607880840000, y: 1.6098 },{ x: 1607880780000, y: 1.6099 },{ x: 1607880720000, y: 1.6098 },{ x: 1607880660000, y: 1.6096 },{ x: 1607880600000, y: 1.6097 },{ x: 1607880540000, y: 1.61 },{ x: 1607880480000, y: 1.6099 },{ x: 1607880420000, y: 1.6101 },{ x: 1607880360000, y: 1.61 },{ x: 1607880300000, y: 1.6101 },{ x: 1607880240000, y: 1.61 },{ x: 1607880180000, y: 1.6101 },{ x: 1607880120000, y: 1.6101 },{ x: 1607880060000, y: 1.61 },{ x: 1607880000000, y: 1.6099 },{ x: 1607879940000, y: 1.6099 },{ x: 1607879880000, y: 1.6098 },{ x: 1607879820000, y: 1.61 },{ x: 1607879760000, y: 1.6097 },{ x: 1607879700000, y: 1.6098 },{ x: 1607879640000, y: 1.6096 },{ x: 1607879580000, y: 1.6096 },{ x: 1607879520000, y: 1.6097 },{ x: 1607879460000, y: 1.6096 },{ x: 1607879400000, y: 1.6095 } ]
All right, I was doing it the other way around, and that's why I was not able to reproduce the described error. Well, so now I see the problem, but as I thought, it's caused by passing not sorted (x ascending order) data, what you can notice after opening the browsers console, and see the Highcharts #15 error.
In order to make it work correctly, you need to always make sure that you're passing the data, which is sorted in ascending order (point x values are increasing along with the array element index).
So, to sum up, sort the array:
[
// data here
].sort((a, b) => a.x - b.x)
then change the the way you prepare (slice) the initial data:
data.slice(data.length - 1 - 15, data.length - 1)
and now it should work as expected.
Live examples:
Without React: https://jsfiddle.net/BlackLabel/37cdryg9/
With React: https://codesandbox.io/s/highcharts-react-demo-forked-q3whu
Related
I'm building a graph and I want to be able to click a bar to show some info when clicked, but even though I inserted all information set in the Victory Chart page is not working, could anyone help me, here is the code
<VictoryStack colorScale={['#533AED']}>
{myWeekDataset &&
myWeekDataset.map((data, i) => {
console.log(data)
return (
<VictoryBar
style={{data: {strokeWidth: 0}}}
cornerRadius={{
top: 10,
bottom: 10,
}}
events={
[
{
target: "data",
eventHandlers: {
onClick: () => {
return [{
target: "data",
mutation: (props) => {
console.log('>>>>CLICKED', props)
}
}]
},
},
},
]
}
data={data}
key={i}
/>
);
})}
</VictoryStack>
this is the data
const myWeekDataset = [
[
{x: moment().subtract(7, 'days').format('ddd'), y: 8},
{x: moment().subtract(6, 'days').format('ddd'), y: 10},
{x: moment().subtract(5, 'days').format('ddd'), y: 6},
{x: moment().subtract(4, 'days').format('ddd'), y: 7},
{x: moment().subtract(3, 'days').format('ddd'), y: 4},
{x: moment().subtract(2, 'days').format('ddd'), y: 8},
{x: moment().subtract(1, 'days').format('ddd'), y: 9},
],
];
What am I doing wrong?
I have an eChart grid layout with 4 stacked bar charts and cannot figure out how to assign datazoom (nor have I found any examples of this online).
When I place the datazoom before the series, I DO get a zoom controller but only on one of the charts...
dataZoom: [{type: 'inside', start: 50, end: 100},
{start: 50, end: 100 }
}],
series: [{type: 'scatter'...
I won't post code for now (it's large) in hopes that someone can just tell me where to put the datazoom node.
I have no idea why you charts not working. Without example and with complex data you need to call fortune-teller only. In general datazoom can be easily attached to series.
var myChart = echarts.init(document.getElementById('main'));
var option = {
xAxis: [{
type: 'category',
gridIndex: 0
},
{
type: 'category',
gridIndex: 1
}
],
yAxis: [{
gridIndex: 0
},
{
gridIndex: 1
}
],
dataset: {
source: [
['product', '2012', '2013', '2014', '2015', '2016', '2017'],
['Matcha Latte', 41.1, 30.4, 65.1, 53.3, 83.8, 98.7],
['Milk Tea', 86.5, 92.1, 85.7, 83.1, 73.4, 55.1],
['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4, 65.2, 82.5],
['Walnut Brownie', 55.2, 67.1, 69.2, 72.4, 53.9, 39.1]
]
},
grid: [{
bottom: '55%'
},
{
top: '55%'
}
],
series: [{
type: 'bar',
xAxisIndex: 1,
yAxisIndex: 1,
encode: {
x: 'product',
y: '2012'
}
}, {
type: 'bar',
xAxisIndex: 1,
yAxisIndex: 1,
encode: {
x: 'product',
y: '2013'
}
}, {
type: 'bar',
stack: 'st1',
encode: {
x: 'product',
y: '2014'
}
}, {
type: 'bar',
stack: 'st1',
encode: {
x: 'product',
y: '2015'
}
}],
dataZoom: [{
type: 'slider',
show: true,
xAxisIndex: [0, 1],
start: 1,
end: 70
},
{
type: 'inside',
xAxisIndex: [0, 1],
start: 1,
end: 35
},
],
};
myChart.setOption(option);
<div id="main" style="width: 600px;height:400px;"></div>
<script src="https://cdn.jsdelivr.net/npm/echarts#4.9.0/dist/echarts.min.js"></script>
Hi I want to create a rectangular bar chart in my react native app. Something like below image
I used react-native-chart-kit but its having only one color configuration. I was googling through other carts but did not find the right one to satisfy the referred image. Is there any example with any bar chart library which can be helpful to me
Excuse my code formatting, navigating my way in Stackoverflow.
This is a code example I have used before, change of padding and color is up too you.
/* App.js */
var React = require('react');
var Component = React.Component;
var CanvasJSReact = require('./canvasjs.react');
var CanvasJS = CanvasJSReact.CanvasJS;
var CanvasJSChart = CanvasJSReact.CanvasJSChart;
class App extends Component {
constructor() {
super();
this.toggleDataSeries = this.toggleDataSeries.bind(this);
}
toggleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dazaSeries.visible) {
e.dataSeries.visible = false;
}
else{
e.dataSeries.visible = true;
}
this.chart.render();
}
render() {
const options = {
animationEnabled: true,
title:{
text: "All Time Summer Olympic Medals"
},
legend: {
verticalAlign: "center",
horizontalAlign: "right",
reversed: true,
cursor: "pointer",
fontSize: 16,
itemclick: this.toggleDataSeries
},
toolTip: {
shared: true
},
data: [
{
type: "stackedColumn100",
name: "Gold",
showInLegend: true,
color: "#D4AF37",
dataPoints: [
{ label: "United States", y:1118},
{ label: "Soviet Union", y:473},
{ label: "Great Britain", y:273},
{ label: "France", y:243},
{ label: "Germany", y:269},
{ label: "Italy", y:243},
{ label: "Sweden", y:195},
{ label: "China", y:236},
{ label: "Russia", y:194},
{ label: "East Germany", y:192}
]
},
{
type: "stackedColumn100",
name: "Silver",
showInLegend: true,
color: "#C0C0C0",
dataPoints: [
{ label: "United States", y: 897},
{ label: "Soviet Union", y: 376},
{ label: "Great Britain", y: 299},
{ label: "France", y: 272},
{ label: "Germany", y: 272},
{ label: "Italy", y: 212},
{ label: "Sweden", y: 210},
{ label: "China", y: 189},
{ label: "Russia", y: 156},
{ label: "East Germany", y: 165}
]
},
{
type: "stackedColumn100",
name: "Bronze",
showInLegend: true,
color: "#CD7F32",
dataPoints: [
{ label: "United States", y: 789},
{ label: "Soviet Union", y: 355},
{ label: "Great Britain", y: 303},
{ label: "France", y: 310},
{ label: "Germany", y: 283},
{ label: "Italy", y: 236},
{ label: "Sweden", y: 233},
{ label: "China", y: 174},
{ label: "Russia", y: 187},
{ label: "East Germany", y: 162}
]
}
]
}
return (
<div>
<CanvasJSChart options = {options}
onRef={ref => this.chart = ref}
/>
{/*You can get reference to the chart instance as shown above using onRef. This allows you to access all chart properties and methods*/}
</div>
);
}
}
module.exports = App;
I am using cytoscape.js version 3.7.0 to show a relation graph.The desired effect is when click one node, the other nodes and edges turn to unusable state.I do not find one attribute to achieve the goal.I am trying to another way: add click event to node, when the node is clicked, set all element "opacity":"0.2", "text-opacity":"0", then set the current node "opacity":"1", "text-opacity":"1", the opacity attribute is work, but the text-opacity is not, only scroll the mouse to zoom-in the graph, the label text on nodes and edges are invisible, scroll the mouse to zoom-out the graph the label text visible again.In my submission, when "text-opacity":"0" been setted, whether zoom or not, the label text should be invisible.
cytoscape.js version is 3.7.0.
I tried to added click event to node, when the node is clicked, set all element "opacity":"0.2", "text-opacity":"0", then set the current node "opacity":"1", "text-opacity":"1", only scroll the mouse to zoom-in the graph the "text-opacity":"0", it worked.
<!DOCTYPE html>
<html>
<head>
<title>Learning Cytoscape.js</title>
<style type="text/css">
/* cytoscape graph */
#cy {
height: 600px;
width: 1200px;
background-color: #00f9f9;
}
</style>
<script src="jquery-2.1.4.min.js"></script>
<script src="cytoscape.min.js"></script>
<script>
let highlightLineWidth = "3px";
let normalLineWidth = "1px";
$(function () {
let edgeMouseOverHandler = function (evt) {
evt.target.style('width', highlightLineWidth);
};
let edgeMouseOutHandler = function (evt) {
evt.target.style('width', normalLineWidth);
};
let nodeMouseOverHandler = function (evt) {
evt.target.connectedEdges().style('width', highlightLineWidth);
};
let nodeMouseOutHandler = function (evt) {
evt.target.connectedEdges().style('width', normalLineWidth);
};
let cy = cytoscape({
container: document.getElementById('cy'),
style: [
{
selector: 'node[label = "Person"]',
css: {
'background-color': '#6FB1FC', 'content': 'data(name)', "font-size": "5px",
"overlay-opacity": "0",
"text-valign": "center",
"text-halign": "center",
"width": "50px",
"height": "50px",
"shape": "circle"
}
},
{
selector: 'node[label = "Movie"]',
css: {
'background-color': '#F5A45D', 'content': 'data(title)', "font-size": "5px",
"text-valign": "center",
"text-halign": "center",
"width": "50px",
"height": "50px",
"shape": "circle",
"overlay-opacity": "0"
}
},
{
selector: 'edge',
css: {
'content': 'data(relationship)', 'target-arrow-shape': 'vee', "font-size": "5px",
'curve-style': 'bezier',
"line-style": "solid",
"width": normalLineWidth,
"overlay-opacity": "0",
}
}
],
elements: {
nodes: [
{data: {id: '172', name: 'Tom', label: 'Person'}, position: { x: 300, y: 300 }},
{data: {id: '173', name: 'Jack', label: 'Person'}, position: { x: 400, y: 230 }},
{data: {id: '174', name: 'Mike', label: 'Person'}, position: { x: 210, y: 350 }},
{data: {id: '175', name: 'Lucy', label: 'Person'}, position: { x: 80, y: 60 }},
{data: {id: '183', title: 'ABC', label: 'Movie'}, position: { x: 370, y: 390 }},
{data: {id: '184', title: 'EFG', label: 'Movie'}, position: { x: 200, y: 100 }},
{data: {id: '185', title: 'movie3', label: 'Movie'}, position: { x: 130, y: 165 }},
{data: {id: '186', title: 'movie4', label: 'Movie'}, position: { x: 278, y: 55 }},
{data: {id: '187', title: 'movie5', label: 'Movie'}, position: { x: 180, y: 30 }},
{data: {id: '188', title: 'movie6', label: 'Movie'}, position: { x: 90, y: 290 }},
{data: {id: '189', title: 'movie7', label: 'Movie'}, position: { x: 45, y: 150 }},
{data: {id: '190', title: 'movie8', label: 'Movie'}, position: { x: 250, y: 200 }},
{data: {id: '191', title: 'movie9', label: 'Movie'}, position: { x: 300, y: 400 }},
{data: {id: '192', title: 'movie10', label: 'Movie'}, position: { x: 500, y: 300 }},
{data: {id: '193', title: 'movie11', label: 'Movie'}, position: { x: 280, y: 120 }},
{data: {id: '194', title: 'movie112', label: 'Movie'}, position: { x: 80, y: 196 }},
],
edges: [{data: {source: '172', target: '183', relationship: 'like'}},
{data: {source: '172', target: '185', relationship: 'like'}},
{data: {source: '173', target: '187', relationship: 'like'}},
{data: {source: '174', target: '188', relationship: 'like'}},
{data: {source: '175', target: '184', relationship: 'like'}},
{data: {source: '172', target: '183', relationship: 'like'}},
{data: {source: '172', target: '192', relationship: 'like'}},
{data: {source: '172', target: '194', relationship: 'like'}},
{data: {source: '172', target: '190', relationship: 'like'}},
{data: {source: '172', target: '183', relationship: 'like'}},
]
},
layout: {
name: 'preset',
}
});
bindEventHandler();
console.log("--------------------------");
cy.on('click', function (event) {
if (event.target === cy) {
cy.elements()
.style("opacity", 1)
.style("events", "yes");
console.log('tap on background');
} else {
console.log('tap on some element');
}
});
cy.on('click', 'node', function (evt) {
console.log("======================");
console.log(evt.target.style());
let toHighlightElements = getToHighlightElements(evt);
// cy.startBatch();
cy.elements().style({"events":"no", "opacity":"0.2", "text-opacity":"0"});
console.log("+++++++++++++++++++++++");
console.log(evt.target.style());
toHighlightElements
.style("opacity", 1);
evt.target.connectedEdges().style("width", highlightLineWidth);
// cy.endBatch();
});
function getToHighlightElements(evt) {
let result = cy.collection();
let tapNode = evt.target;
result.merge(tapNode).merge(tapNode.neighborhood());
return result;
}
function getToIgnoreElements(eles) {
if (eles) {
return cy.elements().unmerge(eles);
} else {
return cy.elements();
}
}
function bindEventHandler() {
cy.on('mouseover', 'edge', edgeMouseOverHandler);
cy.on('mouseout', 'edge', edgeMouseOutHandler);
cy.on('mouseover', 'node', nodeMouseOverHandler);
cy.on('mouseout', 'node', nodeMouseOutHandler);
}
});
</script>
</head>
<body>
<div id="cy"></div>
</body>
</html>
Describe expected : when set "text-opacity":"0" the label text on element is invisible.
Actual results: after set the style, scroll the mouse to zoom-in the graph, text invisible, scroll the mouse to zoom-out the graph, the text visible again.
I am now using Dojo to show a line chart. but I don't know how to change the series line color, would anyone help? thx.
var chart1 = new dc.Chart("test1");
chart1.addPlot("default", { type: "Default", lines: true, markers: true, tension: 1 });
chart1.addAxis("x", { majorTick: { stroke: "black", length: 5 }, minorTick: { stroke: "black", length: 1} });
chart1.addAxis("y", { vertical: true, majorTick: { stroke: "black", length: 5 }, minorTick: { stroke: "black", length: 1} });
chart1.addSeries("Series A", [{ x: 0.5, y: 5 }, { x: 1.5, y: 1.5 }, { x: 2, y: 9 }, { x: 5, y: 0.3}]);
chart1.addSeries("Series B", [{ x: 0.3, y: 8 }, { x: 4, y: 6, tooltip: "Custom tooltip" }, { x: 5.5, y: 2}]);
chart1.addSeries("Series C", [{ x: 0.8, y: 6 }, { x: 8, y: 1, tooltip: "Custom tooltip" }, { x: 7, y: 2}]);
chart1.addSeries("Series D", [{ x: 0.1,y: 5}, { x: 2, y: 3, tooltip: "Custom tooltip" }, { x: 4, y: 5}]);
var anim1a = new dc.action2d.Magnify(chart1, "default");
var anim1b = new dc.action2d.Tooltip(chart1, "default");
chart1.render();
for Series A, Series B,Series C,Series D,I want to use my-defined color to show them, anyone can help?
You can probably also provide the color in your series for it to be used by the plot. Something like the following:
chart1.addSeries("Series A",
[{ x: 0.5, y: 5 }, { x: 1.5, y: 1.5 }, { x: 2, y: 9 }, { x: 5, y: 0.3}],
{ stroke: "green" });
You can change the colors by using the setTheme() function while defining your chart.
Must look like :
require(["dojox/charting/Chart", "dojox/charting/themes/Shrooms", "dojox/charting/plot2d/Areas", ...],
function(Chart, Shrooms, Areas, ...){
new Chart(node)
addPlot("default", { type: Areas, tension: "X" })
setTheme(Shrooms)
addSeries("Series A", [1, 2, 0.5, 1.5, 1, 2.8, 0.4])
addSeries("Series B", [2.6, 1.8, 2, 1, 1.4, 0.7, 2])
addSeries("Series C", [6.3, 1.8, 3, 0.5, 4.4, 2.7, 2])
render();
});
In this example the Theme "Shrooms" will be loaded.
Here you can see, what themes are available for Charts:
http://demos.dojotoolkit.org/demos/chartTypes/demo.html
and in the dojo API you can find them under dojox/charting/themes.
Here's a good tutorial how you can define themes by yourself:
http://dojotoolkit.org/documentation/tutorials/1.9/charting/
Regards, Miriam