fslaborg / fsharp.charting Goto Github PK
View Code? Open in Web Editor NEWCharting library suitable for interactive F# scripting
Home Page: http://fslab.org/FSharp.Charting/
License: Other
Charting library suitable for interactive F# scripting
Home Page: http://fslab.org/FSharp.Charting/
License: Other
Trying to run the F# Charting Library From OSX using Xamarin Studio and Mono 3.2. I downloaded the latest version of FSharp.Charting.Gtk.0.90.5 using the nuget package manager.
I then created a new script file and tried to run the following code:
#load "/packages/FSharp.Charting.Gtk.0.90.5/FSharp.Charting.Gtk.fsx"
open FSharp.Charting
Chart.Line [ for x in 0 .. 10 -> x, x*x ]
This encountered several errors, the first being that it couldn’t find the file FSharp.Charting.Gtk.fsx, this was fixed by prefixing “..” to the path.
After fixing this, the next error I get is:
“error FS0078: Unable to find the file 'gtk-sharp.dll'”
I can fix this directly by adding the following line to the top of FSharp.Charting.Gtk.fsx
Following these changes the sample code above is able to work as expected.
I think the #I reference might be useful to include after a Mac OSX check (I think it can always be found there, but am not sure).
Outside of that, this works great! Am totally jazzed on this GTK/Oxyplot combination.
In FSharpChart, when setting the name property of a Pie chart, it would appear in the window title when showing displayed
In FSharp.Charting, it doesn't happen any more, you always get "ChartType (number)" even when you set the name explicitly
In FSharpChart we could use ChartFormUtilities.ProvideTitle
, but there's no equivalent in FSharp.Charting. This is needed when you want to use ChartControl
directly to embed in an application instead of using it in FSI. The ShowChart
function uses the ProvideTitle
function to set the title of the form it creates, but if you need to show the chart any other way, there's currently no way to get at the title that would be generated
I have a clustering algorithm which generates 14 Charts (for every optimization step one)
I'd like to combine these into a small "movie". Is this possible?
This chart configures the X Axis font but not the Y Axis. If you reverse the last two lines then you get the other way around. The bug is here: https://github.com/fsharp/FSharp.Charting/blob/master/src/FSharp.Charting.fs#L2139. The ApplyStyles gets called twice but when called for X, the defaults for Y are applied, and vice versa, so only one styling can be active at a time.
#load @"C:\Users\DarkMatter\SkyDrive\Repos\Infer.IDE\packages\FSharp.Charting.0.90.7\FSharp.Charting.fsx"
open FSharp.Charting
open FSharp.Charting.ChartTypes
let xAxisStyle = new LabelStyle(FontSize = 8.0)
let yAxisStyle = new LabelStyle(FontSize = 8.0)
Chart.Line [for i in 0.0 .. 10.0 -> i, i*i ]
|> Chart.WithYAxis(Min = 0.0, Max = 200.0, LabelStyle = yAxisStyle (* , MinorGrid = grid, MajorGrid = grid *), Enabled = true )
|> Chart.WithXAxis(Min = 0.0, Max = 10.0, LabelStyle = xAxisStyle (* , MinorGrid = grid, MajorGrid = grid, *), Enabled = true)
Grid interval by years doesn't work. The following code
Interval = 1.0
IntervalOffsetType = DateTimeIntervalType.Years
will actually interval by 1 day.
I read the source code, I found out that the coresponding relationship should be:
Interval <by> IntervalType
IntervalOffset <by> InterOffsetType
(IntervalOffset means to leave the first grid from zero-offset blank for offset
spaces.)
So probobaily this problem is caused by :
IntervalType
missing in type Grid
.
I found this by check the type LabelStyle, the label interval <by> IntervalType
works well.
The MSDN charting APIs used for FSharp.Charting.dll can also be used to generate Web Charts via the
System.Web.UI.DataVisualization.Charting
namespace.
This is useful functionality that fits well with the design of the library since chart specifications used for data scripting can be migrated into ASP.NET applications. The best way to integrate seems to be to cross-compile FSharp.Charting.fs to be a new package and DLL called
FSharp.Charting.AspNet.dll
Is there support for hit-testing on the charts?
Online documentation is still at 0.90.5 instead of 0.90.6 (see http://fsharp.github.io/FSharp.Charting/ReferencingTheLibrary.html).
#59 switched the version of OxyPlot.Core
and OxyPlot.GtkSharp
to 2014.1.546. This change created two compile errors due to breaking errors in the OxyPlot library. PlotControl
and RefreshPlot
in PlotModel
are no longer available (and the master branch of FSharp.Charting.Gtk
cannot be compiled).
I was experimenting using ExtCore async sequences as specifications of incrementally growing data sets. THis works when I use event-based sources of IObservables.
However for the asyncSeq example below I get a background exception:
#r "packages/ExtCore/lib/net40/ExtCore.dll"
#load "packages/FSharp.Charting/FSharp.Charting.fsx"
open FSharp.Charting
asyncSeq {
yield (1,10)
for i in 0 .. 100 do
do! Async.Sleep 100
yield (i,i*i)
}
|> AsyncSeq.toObservable
|> LiveChart.LineIncremental
val it : ChartTypes.GenericChart = (Chart)
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List1.Enumerator.MoveNextRare() at System.Collections.Generic.List
1.Enumerator.MoveNext()
at System.Windows.Forms.DataVisualization.Charting.ChartArea.GetPointsInterval(List`1 seriesList, Boolean isLogarithmic, Double logarithmicBase, Boolean checkSameInterval, Boolean& sameInterval, Series& series)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetDefaultFromData(Axis axis)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetDefaultFromIndexesOrData(Axis axis, AxisType axisType)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetDefaultAxesValues()
at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetData(Boolean initializeAxes, Boolean checkIndexedAligned)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.ReCalcInternal()
at System.Windows.Forms.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly)
at System.Windows.Forms.DataVisualization.Charting.Chart.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Stopped due to error
I have mono 3.8, I am running F# interactive from within emacs on OS X mavericks.
I downloaded FSharp.Charting.Gtk.0.90.7 from nuget. I put it in ~/Desktop/packages/. I have a script containing the following at ~/Desktop/test.fsx:
open FSharp.Charting
Chart.Line [ for x in 0 .. 10 -> x, x*x ]
Trying to run the three lines above gives the following error:
"> [Loading /Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/FSharp.Charting.Gtk.fsx]
/Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/FSharp.Charting.Gtk.fsx(28,1): warning FS0211: The search directory '/usr/lib/mono/gtk-sharp-2.0' could not be found
2014-09-05 12:49:13.471 mono[7211:d07] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
namespace FSI_0002.FSharp.Charting
val verifyMac : unit -> bool
val isMac : bool
module FsiAutoShow = begin
end
/Users/james/Desktop/stdin(0,1): error FS0078: Unable to find the file 'OxyPlot.dll' in any of
/Library/Frameworks/Mono.framework/Versions/3.8.0/lib/mono/4.5
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0
/Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/.
/Users/james/Desktop/
/Library/Frameworks/Mono.framework/Versions/3.8.0/lib/mono/4.0/
Stopped due to error"
I created symbolic links to OxyPlot.dll and OxyPlot.GtkSharp.dll in /Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/. I then get the following error and and a something called mono-sgen appeared in my dock:
"> [Loading /Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/FSharp.Charting.Gtk.fsx]
/Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/FSharp.Charting.Gtk.fsx(28,1): warning FS0211: The search directory '/usr/lib/mono/gtk-sharp-2.0' could not be found
2014-09-05 14:24:36.773 mono[7551:d07] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
namespace FSI_0002.FSharp.Charting
val verifyMac : unit -> bool
val isMac : bool
module FsiAutoShow = begin
end
Binding session to '/Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/./OxyPlot.dll'...
Binding session to '/Users/james/Desktop/packages/FSharp.Charting.Gtk.0.90.7/./OxyPlot.GtkSharp.dll'...
val it : FSharp.Charting.ChartTypes.GenericChart =
Error: An exception was thrown by the type initializer for Gtk.Widget
"
I could not find a way to change the visibility of Margins on the charts I were creating leading to some funny looking charts:
Looking at the history of FSharp.Charting.fs this has been this way since the file was created in commit 580e694f.
It looks like it can be uncommented without any problems. I'll submit a PR for it soon.
Line 19 - referred to older package 0.82 when it should've been 0.83
It would be nice to have a way to output an in memory image with an optional specified size. Useful for generating charts in a back-end process.
This is also somewhat related to issue #26.
Warning 1 This construct is deprecated. This member is now obsolete. Use the '.WithXYZ(...)' fluent methods or the 'Chart.WithXYZ(...)' pipeline methods instead.
In this case there's no alternative method
Charts must be shown to the user before they can be saved as an image but there is no way to programmatically unshow a chart so the user is left with a pile of windows.
Motivated by http://stackoverflow.com/questions/31305580/fsharpchart-two-scales-on-same-graphic.
I assumed that "customizations" to chart objects were done in a non-mutating way, i.e. a fresh new chart was created with the specified customization, and the original was left unchanged.
But it seems that many customizations are "sticky," as if the original chart object has been mutated. This feels like a bug.
#load "../packages/FSharp.Charting.0.90.10/FSharp.Charting.fsx"
open FSharp.Charting
open System.Windows.Forms.DataVisualization.Charting
// displays, no title. good.
let chart =
[1..10]
|> List.map (fun n -> (n, n))
|> Chart.Line ;;
// displays, with title. good.
chart |> Chart.WithTitle(Text = "Test") ;;
// displays, *with* title. why?
chart ;;
When setting the PropertyDefaults for Charting.Grid to Enabled = false, it will lead to Charting.TickMark Enabled set to false as well.
An additional type check might do the trick:
let internal applyDefaults (chartType:SeriesChartType, target:'a, targetParentType:Type option, targetType:Type, property:PropertyInfo) =
....
(propDefault.ParentType |> Option.forall (fun parentType -> parentType = targetType)) &&
....
PS: This is my first command at all. I hope it is properly stated...Plus many thanks for providing such a great library...
The output is a 300px² blank image. I can make it work by implementing SaveChartAs as an extension like ShowChart, and having them work together, but what I've done is a WorksForMySpecificUseCase™ hack. Someone who knows the code better could probably come up with a more robust solution.
This is true for the various Copy methods as well, but they can't be moved easily.
I'm interested in this functionality:
https://msdn.microsoft.com/en-us/library/dd456729.aspx
Thanks,
Rob
(*
#VALX X value of the data point. No Yes
#VALY Y value of the data point Yes Yes
#SERIESNAME Series name No No
#LABEL Data point label No No
#AXISLABEL Data point axis label No No
#INDEX Data point index in the series No Yes
#PERCENT Percent of the data point Y value Yes Yes
#LEGENDTEXT Series or data point legend text No No
#CUSTOMPROPERTY(XXX) Series or data point XXX custom property value, where XXX is the name of the custom property. No No
#TOTAL Total of all Y values in the series Yes Yes
#AVG Average of all Y values in the series Yes Yes
#MIN Minimum of all Y values in the series Yes Yes
#MAX Maximum of all Y values in the series Yes Yes
#FIRST Y value of the first point in the series Yes Yes
#LAST Y value of the last point in the series Yes Yes
Objects and Properties where keywords can be used
Series and DataPoint
•Label
•AxisLabel
•ToolTip
•Url
•MapAreaAttributes
•PostBackValue
•LegendToolTip
•LegendMapAreaAttributes
•LegendPostBackValue
•LegendUrl
•LegendText
•LabelToolTip
Annotation (only if anchored to the data point using SetAnchor method)
•ToolTip
•Url
•MapAreaAttributes
•PostBackValue
•Text (TextAnnotation)
LegendCellColumn (only for legend items automatically created for series or data points):
•Text
•Tooltip
•Url
•MapAreaAttributes
•PostBackValue
*)
Showing a chart with a log scale that includes a zero coordinate causes a crash. I think this should ignore zero elements.
This does not appear to be displaying data. In fact, the charts are displaying data but the default line thickness etc. make it very hard to see:
Chart.Kagi [ 1; 3; 4; 5; 3; 2; ]
Chart.Kagi [ for x in 0 .. 10 -> x, x*x ]
Renko charts are OK though the defaults are not great. See http://msdn.microsoft.com/en-us/library/dd456639(v=VS.100).aspx for details on Kagi charts
Referencing the FSharp.Charting.Gtk.fsx script in the nuget package doesn't work because of a bug in F# Interactive's resolution of DLLs w.r.t. relative directory #I paths when executing on Mono (or when executing on OSX/Linux).
This means you have to reference the DLLs explicitly, e.g. like this, and you have to remove the references in the script.
#r "../gtk-sharp-2.0/gtk-sharp.dll"
#r "../gtk-sharp-2.0/gdk-sharp.dll"
#r "../gtk-sharp-2.0/atk-sharp.dll"
#r "../gtk-sharp-2.0/glib-sharp.dll"
#r "FSharp.Charting.Gtk.0.90.5/lib/net40/OxyPlot.dll"
#r "FSharp.Charting.Gtk.0.90.5/lib/net40/OxyPlot.GtkSharp.dll"
#r "FSharp.Charting.Gtk.0.90.5/lib/net40/FSharp.Charting.Gtk.dll"
#load "FSharp.Charting.Gtk.0.90.5/FSharp.Charting.Gtk.fsx"
This works:
#load "packages/FSharp.Charting.Gtk.0.90.9/FSharp.Charting.Gtk.fsx"
#load "EventEx-0.1.fsx"
Chart.Line ([ for i in 0.0 .. 10.0 -> i, i*i ])
but this gives an NRE:
Chart.Line ([ for i in 0.0 .. 10.0 -> i, i*i ], XTitle="Time")
trace:
System.NullReferenceException: Object reference not set to an instance of an object.
at <StartupCode$FSharp-Charting-Gtk>.$[email protected](String t) in C:\GitHub\fsharp\FSharp.Charting\src\FSharp.Charting.Gtk.fs:line 729
at Microsoft.FSharp.Core.OptionModule.Iterate[T](FSharpFunc2 action, FSharpOption
1 option)
at <StartupCode$FSharp-Charting-Gtk>.$[email protected](T ch) in C:\GitHub\fsharp\FSharp.Charting\src\FSharp.Charting.Gtk.fs:line 729
at <StartupCode$FSI_0020>.$FSI_0020.main@()
It's not obvious how to do it at first thought, and it's a very common plot
This page:
http://fslab.org/FSharp.Charting/contributing.html
links to this (non-existent) issue list:
https://github.com/fsharp/FSharp.Charting/issues
which redirects to this (empty) PR page:
https://github.com/fsharp/FSharp.Charting/pulls
The list I'm posting to now seems to be a lot more active, but I arrived at the earlier pages through google searches. Does the Contributing page on fslab.org just need updating?
FSharpChart assumed 1..N for the x axis
If you create a chart, call ShowChart(), close the chart by hand and then call ShowChart() again you just get internal crashes due to a NULL reference exception.
Hi @tpetricek, @forki, @ImaginaryDevelopment,
With the FSSF becoming legally established, it probably makes sense to have http://github.com/fsharp be more strictly only those repositories related to points 1 and 2 of the mission statement of the FSSF - e.g. fsharp/fsharp, fsharp/FSharp.Compiler.Service, the editor bindings, language design notes and so on.
As a result, would it be ok to move this repository to http://github.com/fsprojects? There are some highly respected and successful projects in that collection now, so you'll be amongst good company :)
There's a related discussion here: fsharp/fsharp.github.io#19
Moving might be a bit painful as the fsharp.github.io/FSharp.Charting site won't automatically redirect, we will need to add a redirect as there are many links pointing to that URL.
Thanks
Don
Although the OxyPlot.GtkSharp assembly is still using gtk-sharp-2:
juergen@samson:~/shared/fsharp/GtkTest → monodis ./src/GtkTest/bin/Debug/OxyPlot.GtkSharp.dll --assemblyref|head -n 30
AssemblyRef Table
...
3: Version=2.12.0.0
Name=gtk-sharp
Flags=0x00000000
Public Key:
GTK-3 and GTK-2 is not API/ABI compatible. A simple test program results in :
(GtkTest:24195): GLib-GObject-CRITICAL **: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed
(GtkTest:24195): GLib-GObject-CRITICAL **: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed
(GtkTest:24195): GLib-GObject-CRITICAL **: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed
(GtkTest:24195): GLib-GObject-CRITICAL **: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed
(GtkTest:24195): GLib-GObject-CRITICAL **: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed
(GtkTest:24195): GLib-GObject-CRITICAL **: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed
0.90.9 works find works fine on my GNU/Linux system.
Seems to be caused by this commit 9ecbe70
This was one of the bugfixes from FSharpChart 0.55 to 0.56, but it was lost in FSharp.Charting.
This two comits have the original fix:
https://github.com/ovatsus/FSharpChart/commit/e1a53455aacfca8c3525f70b28bc911cd17a9c2c
https://github.com/ovatsus/FSharpChart/commit/79c7a342fa7126e7e78ca337937ebd3d372838fb
There is an appveyor build here, it is is failing because of missing GTK DLLs: https://ci.appveyor.com/project/fsgit/fsharp-charting
When run, the following code silently throws an exception at the line:
let chartControl = new ChartControl(chart),
despite ostensibly running just fine. The message in the output window is:
"A first chance exception of type 'System.InvalidOperationException' occurred in FSharp.Core.dll"
open System
open System.Drawing
open System.Reactive.Linq
open System.Threading
open System.Windows.Forms
open FSharp.Charting
open FSharp.Charting.ChartTypes
// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
[<EntryPoint>]
let main argv =
printfn "%A" argv
let form = new Form()
form.Size <- new Size(800, 600)
let step =
let gen = new Random()
(fun () -> 2.0 * (gen.NextDouble() - 0.5))
let randomWalk =
Observable
.Interval(TimeSpan.FromMilliseconds 200.0)
.ObserveOn SynchronizationContext.Current
|> Observable.scan (fun (x, y) _ -> (x + 1.0, y + step())) (0.0, 0.0)
let chart = LiveChart.FastLineIncremental randomWalk
let chartControl = new ChartControl(chart)
chartControl.Dock <- DockStyle.Fill
form.Controls.Add chartControl
Application.Run(form)
0 // return an integer exit code
Am I doing something that I shouldn't be doing?
#load "../packages/FSharp.Charting.0.90.12/FSharp.Charting.fsx"
open FSharp.Charting
let chart =
[1..10]
|> List.map (fun n -> (n, n))
|> Chart.Line ;;
This displays the chart, as expected. Now close that display window, and try to display the chart again:
chart ;;
Result:
val it : ChartTypes.GenericChart =
Error: Exception has been thrown by the target of an invocation.
Grouped bar charts are a very common charting pattern, but I can't seem to find this on FSharp.Charting. Am I missing something?
For example, see: http://stackoverflow.com/a/15556707
There appears to be no way to name a series on the Stacked Column chart, so the legend just uses generated names. There should be a way to supply the series names e.g. as you can do with the labels for the regular Column charts or similar.
This library is Windows-only so far, as mentioned in the docs: http://fsharp.github.io/FSharp.Charting/.
We would like to make a subset of the functionality available across multiple platforms, so that at least basic chart specifications are portable.
Two approaches to achieving that would be:
We’ve also talked about adding additional backends on Windows, e.g. Excel.
If you need charting on the Mac today, I think I would recommend either
Calling a chart's SaveChartAs instance method without first calling ShowChart causes it to silently emit blank images.
Could not load file or assembly 'FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
where AppDomain.CurrentDomain.GetAssemblies().Dump()
shows that FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
is loaded. I imagine an assembly binding redirect would work, however, I'm in LinqPad where I don't believe that is a nice option.
I've created a ticket on their side as well. http://linqpad.uservoice.com/forums/18302-linqpad-feature-suggestions/suggestions/6292273-f-can-t-specify-fsharp-core-dll-version
Axis ranges from 300 to 300000 result in chart ticks with labels like 29999.9999998 that take up half the chart and make it unreadable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.