-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to show chart grid? #230
Comments
It's been a while since I've worked with this package, so I'm just copying the following from a working app, but hopefully it can at least help point you in the right direction: // https://github.com/d3/d3-format#api-reference
const DEC = ',.2f',
DEC1 = ',.1f',
INT = ',.0f',
SI = ',.3s',
DATE = '%b %d, %Y' // https://github.com/d3/d3-time-format#locale_format
const FORMATS = {
DEC: d3.format(DEC),
DEC1: d3.format(DEC1),
INT: d3.format(INT),
SI: d3.format(SI),
SMART: function (num) {
if (num < 100) {
return d3.format(DEC)(num)
} else if (num < 10000) {
return d3.format(INT)(num)
} else {
return d3.format(SI)(num)
}
},
DATE: d3.timeFormat(DATE),
}
const SCALES = {
[LINEAR_SCALE]: d3.scaleLinear(),
[LOG_SCALE]: d3.scaleLog(),
}
class Chart extends React.Component {
// chart height is the entire chart, including indicators, but excluding margins
// plot height is the height of the price chart only, also excluding margins
_drawAxes() {
// x axis
this.xScale = techan.scale.financetime()
.range([0, this.chartWidth])
.outerPadding(1)
this.xAxis = d3.axisBottom(this.xScale)
.tickSizeOuter(0)
this.svg.append('g')
.attr('class', 'x axis')
.attr('transform', `translate(0, ${this.chartHeight})`)
// x grid
this.xGrid = d3.axisBottom(this.xScale)
.ticks(4) // FIXME: this draws quarterly lines with daily data, what about intraday/weekly/monthly??
.tickFormat(() => null)
.tickSizeInner(-this.plotHeight)
.tickSizeOuter(-this.plotHeight)
this.svg.append('g')
.attr('class', 'x grid')
.attr('transform', `translate(0, ${this.plotHeight})`)
// y axis
this.yScale = SCALES[this.props.scale]
.range([this.plotHeight, 0])
this.yAxis = d3.axisLeft(this.yScale)
.tickFormat(FORMATS.SMART)
this.svg.append('g')
.attr('class', 'y axis')
this.yAxisRight = d3.axisRight(this.yScale)
.tickSizeOuter(0)
.tickFormat(FORMATS.SMART)
this.svg.append('g')
.attr('class', 'y axis right')
.attr('transform', `translate(${this.chartWidth}, 0)`)
// y grid
this.yGrid = d3.axisLeft(this.yScale)
.tickFormat(() => null)
.tickSizeInner(-this.chartWidth)
.tickSizeOuter(-this.chartWidth)
this.svg.append('g')
.attr('class', 'y grid')
}
} /* relevant styles */
.techan-chart {
.grid path.domain,
.axis path.domain {
stroke: $axis-color;
}
.axis .tick line {
stroke: $axis-tick-color;
}
.grid .tick line {
stroke: $grid-color;
opacity: $grid-opacity;
}
} |
Thank you so much # @briancappello for the fast answer |
No problem. I updated the code a bit to add the missing constants and explain the difference between chartHeight and plotHeight, hope it's helpful :) |
Are you by chance using React in your app? (I'd like to open source the charting component but I don't really know to package it, and I don't really have time to figure it for the forseeable future) |
Yes I’m using React in my app. Did you wrapped techan with React? |
I was wondering abou that , too. Thanks!
Viele Grüße,
Ulrich
…-------- Ursprüngliche Nachricht --------
Von: Brian Cappello <notifications@github.com>
Datum: 01.10.18 16:11 (GMT+01:00)
An: "andredumas/techan.js" <techan.js@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Betreff: Re: [andredumas/techan.js] How to show chart grid? (#230)
It's been a while since I've worked with this package, so I'm just copying the following from a working app, but hopefully it can at least help point you in the right direction:
_drawAxes() {
// x axis
this.xScale = techan.scale.financetime()
.range([0, this.chartWidth])
.outerPadding(1)
this.xAxis = d3.axisBottom(this.xScale)
.tickSizeOuter(0)
this.svg.append('g')
.attr('class', 'x axis')
.attr('transform', `translate(0, ${this.chartHeight})`)
// x grid
this.xGrid = d3.axisBottom(this.xScale)
.ticks(4) // FIXME: this draws quarterly lines with daily data, what about intraday/weekly/monthly??
.tickFormat(() => null)
.tickSizeInner(-this.plotHeight)
.tickSizeOuter(-this.plotHeight)
this.svg.append('g')
.attr('class', 'x grid')
.attr('transform', `translate(0, ${this.plotHeight})`)
// y axis
this.yScale = SCALES[this.props.scale]
.range([this.plotHeight, 0])
this.yAxis = d3.axisLeft(this.yScale)
.tickFormat(FORMATS.SMART)
this.svg.append('g')
.attr('class', 'y axis')
this.yAxisRight = d3.axisRight(this.yScale)
.tickSizeOuter(0)
.tickFormat(FORMATS.SMART)
this.svg.append('g')
.attr('class', 'y axis right')
.attr('transform', `translate(${this.chartWidth}, 0)`)
// y grid
this.yGrid = d3.axisLeft(this.yScale)
.tickFormat(() => null)
.tickSizeInner(-this.chartWidth)
.tickSizeOuter(-this.chartWidth)
this.svg.append('g')
.attr('class', 'y grid')
}
.techan-chart {
.grid path.domain,
.axis path.domain {
stroke: $axis-color;
}
.axis .tick line {
stroke: $axis-tick-color;
}
.grid .tick line {
stroke: $grid-color;
opacity: $grid-opacity;
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/andredumas/techan.js","title":"andredumas/techan.js","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/andredumas/techan.js"}},"updates":{"snippets":[{"icon":"PERSON","message":"@briancappello in #230: It's been a while since I've worked with this package, so I'm just copying the following from a working app, but hopefully it can at least help point you in the right direction:\r\n\r\n```javascript\r\n _drawAxes() {\r\n // x axis\r\n this.xScale = techan.scale.financetime()\r\n .range([0, this.chartWidth])\r\n .outerPadding(1)\r\n\r\n this.xAxis = d3.axisBottom(this.xScale)\r\n .tickSizeOuter(0)\r\n\r\n this.svg.append('g')\r\n .attr('class', 'x axis')\r\n .attr('transform', `translate(0, ${this.chartHeight})`)\r\n\r\n // x grid\r\n this.xGrid = d3.axisBottom(this.xScale)\r\n .ticks(4) // FIXME: this draws quarterly lines with daily data, what about intraday/weekly/monthly??\r\n .tickFormat(() =\u003e null)\r\n .tickSizeInner(-this.plotHeight)\r\n .tickSizeOuter(-this.plotHeight)\r\n\r\n this.svg.append('g')\r\n .attr('class', 'x grid')\r\n .attr('transform', `translate(0, ${this.plotHeight})`)\r\n\r\n // y axis\r\n this.yScale = SCALES[this.props.scale]\r\n .range([this.plotHeight, 0])\r\n\r\n this.yAxis = d3.axisLeft(this.yScale)\r\n .tickFormat(FORMATS.SMART)\r\n\r\n this.svg.append('g')\r\n .attr('class', 'y axis')\r\n\r\n this.yAxisRight = d3.axisRight(this.yScale)\r\n .tickSizeOuter(0)\r\n .tickFormat(FORMATS.SMART)\r\n\r\n this.svg.append('g')\r\n .attr('class', 'y axis right')\r\n .attr('transform', `translate(${this.chartWidth}, 0)`)\r\n\r\n // y grid\r\n this.yGrid = d3.axisLeft(this.yScale)\r\n .tickFormat(() =\u003e null)\r\n .tickSizeInner(-this.chartWidth)\r\n .tickSizeOuter(-this.chartWidth)\r\n\r\n this.svg.append('g')\r\n .attr('class', 'y grid')\r\n }\r\n```\r\n\r\n```scss\r\n.techan-chart {\r\n .grid path.domain,\r\n .axis path.domain {\r\n stroke: $axis-color;\r\n }\r\n .axis .tick line {\r\n stroke: $axis-tick-color;\r\n }\r\n\r\n .grid .tick line {\r\n stroke: $grid-color;\r\n opacity: $grid-opacity;\r\n }\r\n}\r\n```"}],"action":{"name":"View Issue","url":"#230 (comment)"}}}
[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "#230 (comment)",
"url": "#230 (comment)",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [andredumas/techan.js] How to show chart grid? (#230)",
"sections": [
{
"text": "",
"activityTitle": "**Brian Cappello**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@briancappello",
"facts": [
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"andredumas/techan.js\",\n\"issueId\": 230,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"andredumas/techan.js\",\n\"issueId\": 230\n}"
},
{
"targets": [
{
"os": "default",
"uri": "#230 (comment)"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 386434506\n}"
}
],
"themeColor": "26292E"
}
]
|
Yea, or at least I tried haha. It mostly works I created a gist here with the meat of the code (I'm sure I missed a few imports). I also started a refactor on the indicator support a long while ago that I'm pretty sure is in a broken state but that exists too |
You can consider that code as MIT licensed, and if you let me know what imports I missed, i'd be happy to add the files |
What exactly do you need to export the component @briancappello ? I don't understand your trouble |
@briancappello I can't show the chart grid 😢 My chart looks like: Here's my legacy code, can you help me?
|
@briancappello Hi Brian!! I need help with chart grid 😢 I tried to implement your solution but I could not did it. Can you show me one picture of your chart grid to check if it is what I need. Or can you quickly check my code? Maybe you can see something wrong fast. Thank you so much for all this help 😄 |
Hey, I've got some personal stuff on my plate at the moment that's chewing
up all of my time and mental capacity but I would be happy to help
hopefully next week, sorry I can't be more responsive right now :(
…On Thu, Oct 11, 2018, 9:15 AM Ignacio F. Castillejo Gómez < ***@***.***> wrote:
@briancappello <https://github.com/briancappello> Hi Brian!! I need help
with chart grid 😢 I tried to implement your solution but I could not did
it. Can you show me one picture of your chart grid to check if it is what I
need. Or can you quickly check my code? Maybe you can see something wrong
fast.
Thank you so much for all this help 😄
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#230 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACdSLOMUgCx0nMkAeJt5-apnLjkGUBuqks5uj2B5gaJpZM4XCIXK>
.
|
Don't worry!!! 😄 Thank you @briancappello I will be waiting for you next week |
Tomorrow I'll try this code: https://bl.ocks.org/d3noob/c506ac45617cf9ed39337f99f8511218 |
Hey @icastillejogomez, sorry for the delay (I ended up having to fix some of my backend code before I could get this running in order to take a screenshot, woops). I'm gonna spend some time this weekend to see if I can't get my chart code released as a library, hopefully it goes well :) I skimmed your code, didn't notice anything immediately obviously wrong, but if that screenshot is what you're looking for I can take a closer look |
Thank you so much @briancappello I now showing X axis grid but I can't display the Y axis grid. For other side... it is possible display more than two SMA in chart? I coded the for loop and work out for one and two SMA but with three SMA crash. I suppose I have a bug. |
I'm developing a new trade app and we need to show the chart grid in our chart. Is it possible?
The text was updated successfully, but these errors were encountered: